mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: confusing error if composite literal field is a method
When looking for the field specified in a composite literal, check that the specified name is actually a field and not a method. Fixes #29855. Change-Id: Id77666e846f925907b1eec64213b1d25af8a2466 Reviewed-on: https://go-review.googlesource.com/c/158938 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
c6e47069af
commit
6d781decad
5 changed files with 29 additions and 6 deletions
|
|
@ -1180,7 +1180,7 @@ func lookdot0(s *types.Sym, t *types.Type, save **types.Field, ignorecase bool)
|
|||
c := 0
|
||||
if u.IsStruct() || u.IsInterface() {
|
||||
for _, f := range u.Fields().Slice() {
|
||||
if f.Sym == s || (ignorecase && f.Type.Etype == TFUNC && f.Type.Recv() != nil && strings.EqualFold(f.Sym.Name, s.Name)) {
|
||||
if f.Sym == s || (ignorecase && f.IsMethod() && strings.EqualFold(f.Sym.Name, s.Name)) {
|
||||
if save != nil {
|
||||
*save = f
|
||||
}
|
||||
|
|
@ -1420,7 +1420,7 @@ func expandmeth(t *types.Type) {
|
|||
}
|
||||
|
||||
// dotpath may have dug out arbitrary fields, we only want methods.
|
||||
if f.Type.Etype != TFUNC || f.Type.Recv() == nil {
|
||||
if !f.IsMethod() {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -1631,7 +1631,7 @@ func ifacelookdot(s *types.Sym, t *types.Type, ignorecase bool) (m *types.Field,
|
|||
}
|
||||
}
|
||||
|
||||
if m.Type.Etype != TFUNC || m.Type.Recv() == nil {
|
||||
if !m.IsMethod() {
|
||||
yyerror("%v.%v is a field, not a method", t, s)
|
||||
return nil, followptr
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue