cmd/compile: confusing error if composite literal field that is a method is specified #29855
Labels
FrozenDueToAge
NeedsFix
The path to resolution is known, but the work has not been done.
Suggested
Issues that may be good for new contributors looking for work to do.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What did you do?
Playground link: https://play.golang.org/p/llL2iikbJmd
(Note: the field is called
GlobalName
but the composite literal specifies the incorrect fieldName
, which is also a method).What did you expect to see?
An error message telling me that I'm trying to declare a composite literal field which doesn't exist (or is a method, not a struct field).
What did you see instead?
This lead to some confusion - in my case because the name of the method (
Name
) was similar to the name of the field I was trying to declare (GlobalName
). The issue occurred because a dependency I was using changed theName
field toGlobalName
and introduced an accessor method called(T).Name()
. So I was in a larger process of code repair.The struct in question also had a number of embedded fields, so it took a moment before I found the root cause (that there was
Name
method defined far away).See also #23609 which improved error messages for embedding but perhaps made things more confusing in this case.
The text was updated successfully, but these errors were encountered: