aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2022-09-26 12:47:41 -0700
committerRobert Griesemer <gri@google.com>2022-09-27 21:59:09 +0000
commitb16501c08b37235a67e2fc5b506f169152db57ae (patch)
tree066e2f1c26034de79e0871e00838a77d02d1aa8e /src
parent3b5188ed2c38ba29aa586db7af243c3f3be27944 (diff)
downloadgo-b16501c08b37235a67e2fc5b506f169152db57ae.tar.xz
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>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/types2/expr.go6
-rw-r--r--src/go/types/expr.go2
2 files changed, 2 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/types2/expr.go b/src/cmd/compile/internal/types2/expr.go
index 3e82e4bcca..c700667034 100644
--- a/src/cmd/compile/internal/types2/expr.go
+++ b/src/cmd/compile/internal/types2/expr.go
@@ -1418,11 +1418,7 @@ 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.Key, _MissingLitField, "unknown field '%s' in struct literal of type %s", key.Value, base)
- } else {
- check.errorf(kv.Key, _MissingLitField, "unknown field %s in struct literal", key.Value)
- }
+ check.errorf(kv.Key, _MissingLitField, "unknown field %s in struct literal of type %s", key.Value, base)
continue
}
fld := fields[i]
diff --git a/src/go/types/expr.go b/src/go/types/expr.go
index 12f73947fd..ebb107b8c0 100644
--- a/src/go/types/expr.go
+++ b/src/go/types/expr.go
@@ -1397,7 +1397,7 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
}
i := fieldIndex(utyp.fields, check.pkg, key.Name)
if i < 0 {
- check.errorf(kv, _MissingLitField, "unknown field %s in struct literal", key.Name)
+ check.errorf(kv, _MissingLitField, "unknown field %s in struct literal of type %s", key.Name, base)
continue
}
fld := fields[i]