1
0
mirror of https://github.com/golang/go synced 2024-11-17 16:14:42 -07:00
go/test/fixedbugs/issue19482.go
Robert Griesemer b16501c08b go/types, types2: use "unknown field f in struct literal of type S" in error messages
This is a compromise of the error reported by the compiler (quotes
around field name removed) and the error reported by the type checkers
(added mention of struct type).

For #55326.

Change-Id: Iac4fb5c717f17c6713e90d327d39e68d3be40074
Reviewed-on: https://go-review.googlesource.com/c/go/+/434815
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2022-09-27 21:59:09 +00:00

35 lines
1.1 KiB
Go

// errorcheck
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Compiler rejected initialization of structs to composite literals
// in a non-static setting (e.g. in a function)
// when the struct contained a field named _.
package p
type T struct {
_ string
}
func ok() {
var x = T{"check"}
_ = x
_ = T{"et"}
}
var (
y = T{"stare"}
w = T{_: "look"} // ERROR "invalid field name _ in struct initializer|expected struct field name|unknown field _ in struct literal of type T"
_ = T{"page"}
_ = T{_: "out"} // ERROR "invalid field name _ in struct initializer|expected struct field name|unknown field _ in struct literal of type T"
)
func bad() {
var z = T{_: "verse"} // ERROR "invalid field name _ in struct initializer|expected struct field name|unknown field _ in struct literal of type T"
_ = z
_ = T{_: "itinerary"} // ERROR "invalid field name _ in struct initializer|expected struct field name|unknown field _ in struct literal of type T"
}