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 11package p 12 13type T struct { 14 _ string 15} 16 17func ok() { 18 var x = T{"check"} 19 _ = x 20 _ = T{"et"} 21} 22 23var ( 24 y = T{"stare"} 25 w = T{_: "look"} // ERROR "invalid field name _ in struct initializer|expected struct field name|unknown field _ in struct literal of type T" 26 _ = T{"page"} 27 _ = T{_: "out"} // ERROR "invalid field name _ in struct initializer|expected struct field name|unknown field _ in struct literal of type T" 28) 29 30func bad() { 31 var z = T{_: "verse"} // ERROR "invalid field name _ in struct initializer|expected struct field name|unknown field _ in struct literal of type T" 32 _ = z 33 _ = T{_: "itinerary"} // ERROR "invalid field name _ in struct initializer|expected struct field name|unknown field _ in struct literal of type T" 34} 35