diff --git a/src/cmd/compile/internal/gc/noder.go b/src/cmd/compile/internal/gc/noder.go index fc6c5587df4..1d491d2acca 100644 --- a/src/cmd/compile/internal/gc/noder.go +++ b/src/cmd/compile/internal/gc/noder.go @@ -569,7 +569,8 @@ func (p *noder) expr(expr syntax.Expr) *Node { lineno = p.makeXPos(expr.Rbrace) return n case *syntax.KeyValueExpr: - return p.nod(expr, OKEY, p.expr(expr.Key), p.wrapname(expr.Value, p.expr(expr.Value))) + // use position of expr.Key rather than of expr (which has position of ':') + return p.nod(expr.Key, OKEY, p.expr(expr.Key), p.wrapname(expr.Value, p.expr(expr.Value))) case *syntax.FuncLit: return p.funcLit(expr) case *syntax.ParenExpr: diff --git a/test/fixedbugs/issue24339.go b/test/fixedbugs/issue24339.go new file mode 100644 index 00000000000..0670becdfe1 --- /dev/null +++ b/test/fixedbugs/issue24339.go @@ -0,0 +1,20 @@ +// errorcheck + +// Copyright 2018 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 p + +// Use a diffent line number for each token so we can +// check that the error message appears at the correct +// position. +var _ = struct{}{ /*line :20:1*/foo /*line :21:1*/: /*line :22:1*/0 } + + + + + + + +// ERROR "unknown field 'foo'" \ No newline at end of file