Skip to content

Commit

Permalink
[dev.typeparams] cmd/compile/internal/types2: report correct line num…
Browse files Browse the repository at this point in the history
…ber for missing key

Use the Key position of a syntax.KeyValueExpr (not the position of the
":") when reporting an error for a missing key.

(In go/types, the KeyValueExpr position is the start of the expression
not the ":", so there this works as expected.)

Change-Id: I74147d245927847274cf4e53b4f03dbb5110c324
Reviewed-on: https://go-review.googlesource.com/c/go/+/276813
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
  • Loading branch information
griesemer committed Dec 10, 2020
1 parent edf80c4 commit dbce27d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/types2/expr.go
Expand Up @@ -1277,9 +1277,9 @@ func (check *Checker) exprInternal(x *operand, e syntax.Expr, hint Type) exprKin
i := fieldIndex(utyp.fields, check.pkg, key.Value)
if i < 0 {
if check.conf.CompilerErrorMessages {
check.errorf(kv, "unknown field '%s' in struct literal of type %s", key.Value, base)
check.errorf(kv.Key, "unknown field '%s' in struct literal of type %s", key.Value, base)
} else {
check.errorf(kv, "unknown field %s in struct literal", key.Value)
check.errorf(kv.Key, "unknown field %s in struct literal", key.Value)
}
continue
}
Expand Down
1 change: 0 additions & 1 deletion test/run.go
Expand Up @@ -2004,7 +2004,6 @@ var excluded = map[string]bool{
"fixedbugs/issue22200.go": true, // types2 doesn't produce "stack frame too large" error
"fixedbugs/issue22200b.go": true, // types2 doesn't produce "stack frame too large" error
"fixedbugs/issue23732.go": true, // types2 reports different (but ok) line numbers
"fixedbugs/issue24339.go": true, // types2 reports wrong line number
"fixedbugs/issue25507.go": true, // types2 doesn't produce "stack frame too large" error
"fixedbugs/issue25958.go": true, // types2 doesn't report a follow-on error (pref: types2)
"fixedbugs/issue28079b.go": true, // types2 reports follow-on errors
Expand Down

0 comments on commit dbce27d

Please sign in to comment.