diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index 94ae32ec2c..1a8056a2a4 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -3095,7 +3095,7 @@ func typecheckcomplit(n *Node) *Node { f := lookdot1(nil, l.Sym, t, t.Fields(), 0) if f == nil { - yyerror("unknown %v field '%v' in struct literal", t, l.Sym) + yyerror("unknown field '%v' in struct literal of type %v", l.Sym, t) continue } fielddup(f.Sym.Name, hash) diff --git a/test/fixedbugs/issue14136.go b/test/fixedbugs/issue14136.go index 928a60bf6b..f9efd05f96 100644 --- a/test/fixedbugs/issue14136.go +++ b/test/fixedbugs/issue14136.go @@ -14,6 +14,6 @@ package main type T struct{} func main() { - t := T{X: 1, X: 1, X: 1, X: 1, X: 1, X: 1, X: 1, X: 1, X: 1, X: 1} // ERROR "unknown T field" + t := T{X: 1, X: 1, X: 1, X: 1, X: 1, X: 1, X: 1, X: 1, X: 1, X: 1} // ERROR "unknown field 'X' in struct literal of type T" var s string = 1 // ERROR "cannot use 1" } diff --git a/test/fixedbugs/issue17631.go b/test/fixedbugs/issue17631.go new file mode 100644 index 0000000000..79b7e8a751 --- /dev/null +++ b/test/fixedbugs/issue17631.go @@ -0,0 +1,22 @@ +// errorcheck + +// Copyright 2016 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. + +package main + +import "time" + +func main() { + _ = struct { + about string + before map[string]uint + update map[string]int + updateTime time.Time + expect map[string]int + }{ + about: "this one", + updates: map[string]int{"gopher": 10}, // ERROR "unknown field 'updates' in struct literal of type" + } +}