1 // expected: cannot use value of type []*main.T as []main.T
2 //
3 // The header names stage4's wording; legacy rejects the same fixture through
4 // go/types with its own phrasing ("cannot use xs (variable of type []*T) as
5 // []T value in assignment"), which is why this fixture is checked by the
6 // restriction suite that runs stage4.
7 //
8 // A store into a struct FIELD, a slice element, a map value and a
9 // through-a-pointer target is an assignment and must be type-checked like one.
10 // stage4 checked only a store into a plain variable, so this compiled and
11 // stored a pointer array where an array of struct values was declared. Reading
12 // it back is not a diagnostic, it is silent garbage: smesh's
13 // nostr.NewTags(list ...*Tag) assigned []*Tag to `List []Tag` and the marmot
14 // codec test died with SIGBUS on the first field read. Legacy rejected it all
15 // along (go/types: "cannot use xs (variable of type []*T) as []T value in
16 // assignment"), so this was also a compilers-disagree bug.
17 package main
18 19 type T struct {
20 n int32
21 }
22 23 type Holder struct {
24 List []T
25 }
26 27 func build(xs []*T) (h *Holder) {
28 h = &Holder{}
29 h.List = xs
30 return h
31 }
32 33 func main() {
34 a := &T{n: 1}
35 h := build([]*T{a})
36 println(len(h.List))
37 }
38