1// errorcheck
2
3// Copyright 2011 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7// Verify that illegal composite literals are detected.
8// Does not compile.
9
10package main
11
12var m map[int][3]int
13
14func f() [3]int
15
16func fp() *[3]int
17
18var mp map[int]*[3]int
19
20var (
21	_ = [3]int{1, 2, 3}[:] // ERROR "slice of unaddressable value"
22	_ = m[0][:]            // ERROR "slice of unaddressable value"
23	_ = f()[:]             // ERROR "slice of unaddressable value"
24
25	_ = 301[:]  // ERROR "cannot slice|attempt to slice object that is not"
26	_ = 3.1[:]  // ERROR "cannot slice|attempt to slice object that is not"
27	_ = true[:] // ERROR "cannot slice|attempt to slice object that is not"
28
29	// these are okay because they are slicing a pointer to an array
30	_ = (&[3]int{1, 2, 3})[:]
31	_ = mp[0][:]
32	_ = fp()[:]
33)
34
35type T struct {
36	i    int
37	f    float64
38	s    string
39	next *T
40}
41
42type TP *T
43type Ti int
44
45var (
46	_ = &T{0, 0, "", nil}               // ok
47	_ = &T{i: 0, f: 0, s: "", next: {}} // ERROR "missing type in composite literal|omit types within composite literal"
48	_ = &T{0, 0, "", {}}                // ERROR "missing type in composite literal|omit types within composite literal"
49	_ = TP{i: 0, f: 0, s: ""}           // ERROR "invalid composite literal type TP"
50	_ = &Ti{}                           // ERROR "invalid composite literal type Ti|expected.*type for composite literal"
51)
52
53type M map[T]T
54
55var (
56	_ = M{{i: 1}: {i: 2}}
57	_ = M{T{i: 1}: {i: 2}}
58	_ = M{{i: 1}: T{i: 2}}
59	_ = M{T{i: 1}: T{i: 2}}
60)
61
62type S struct{ s [1]*M1 }
63type M1 map[S]int
64
65var _ = M1{{s: [1]*M1{&M1{{}: 1}}}: 2}
66