OLD | NEW |
1 // errchk $G -e $D/$F.go | 1 // errchk $G -e $D/$F.go |
2 | 2 |
3 // Copyright 2011 The Go Authors. All rights reserved. | 3 // Copyright 2011 The Go Authors. All rights reserved. |
4 // Use of this source code is governed by a BSD-style | 4 // Use of this source code is governed by a BSD-style |
5 // license that can be found in the LICENSE file. | 5 // license that can be found in the LICENSE file. |
6 | 6 |
7 package main | 7 package main |
8 | 8 |
9 var m map[int][3]int | 9 var m map[int][3]int |
| 10 |
10 func f() [3]int | 11 func f() [3]int |
11 | 12 |
12 func fp() *[3]int | 13 func fp() *[3]int |
| 14 |
13 var mp map[int]*[3]int | 15 var mp map[int]*[3]int |
14 | 16 |
15 var ( | 17 var ( |
16 » _ = [3]int{1,2,3}[:] // ERROR "slice of unaddressable value" | 18 » _ = [3]int{1, 2, 3}[:] // ERROR "slice of unaddressable value" |
17 » _ = m[0][:] // ERROR "slice of unaddressable value" | 19 » _ = m[0][:] // ERROR "slice of unaddressable value" |
18 » _ = f()[:] // ERROR "slice of unaddressable value" | 20 » _ = f()[:] // ERROR "slice of unaddressable value" |
19 » | 21 |
20 // these are okay because they are slicing a pointer to an array | 22 // these are okay because they are slicing a pointer to an array |
21 » _ = (&[3]int{1,2,3})[:] | 23 » _ = (&[3]int{1, 2, 3})[:] |
22 _ = mp[0][:] | 24 _ = mp[0][:] |
23 _ = fp()[:] | 25 _ = fp()[:] |
24 ) | 26 ) |
| 27 |
| 28 type T struct { |
| 29 » i int |
| 30 » f float64 |
| 31 » s string |
| 32 » next *T |
| 33 } |
| 34 |
| 35 var ( |
| 36 » _ = &T{0, 0, "", nil} // ok |
| 37 » _ = &T{i: 0, f: 0, s: "", next: {}} // ok |
| 38 » _ = &T{0, 0, "", {}} // ERROR "missing type in composite
literal" |
| 39 ) |
OLD | NEW |