modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue19482.go (about) 1 // errorcheck 2 3 // Copyright 2017 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 // Compiler rejected initialization of structs to composite literals 8 // in a non-static setting (e.g. in a function) 9 // when the struct contained a field named _. 10 11 package p 12 13 type T struct { 14 _ string 15 } 16 17 func ok() { 18 var x = T{"check"} 19 _ = x 20 _ = T{"et"} 21 } 22 23 var ( 24 y = T{"stare"} 25 w = T{_: "look"} // ERROR "invalid field name _ in struct initializer" 26 _ = T{"page"} 27 _ = T{_: "out"} // ERROR "invalid field name _ in struct initializer" 28 ) 29 30 func bad() { 31 var z = T{_: "verse"} // ERROR "invalid field name _ in struct initializer" 32 _ = z 33 _ = T{_: "itinerary"} // ERROR "invalid field name _ in struct initializer" 34 }