-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go/types, types2: self-contradictory error message when separating the definition and implementation of an interface with anonymous structs in a method signature #54258
Comments
CC @golang/compiler. |
Agreed the error message is unfortunate for not being able to disambiguate that though. /cc @griesemer @findleyr |
Ack, this is unfortunate and confusing. It would be good to clarify that the identity of the I am not sure how high a priority this is, but we do want to continue to improve error messages in the new type checker. (I have not yet checked whether the old type checker produced a better message here). |
@findleyr As part of triage assigning to you for now, but please feel free to unassign! Noted the low-ish priority. |
Reassigning to @dr2chase who volunteered to take a quick look. |
The new type checker is annoying in its parsimony; structs, which can have packages as part of their identity, don't know their own packages. The old type checker was similarly confusing. I have a maybe fix, subject to passing tests. I'm not proud of it.... |
Named structs you can find their package with Named.Obj().Pkg(). Anonymous, non-empty structs you can find their package with Struct.Field(0).Pkg(). (A struct definition can't span multiple packages, so all of its fields must exist in the same package.) The anonymous, empty struct is identical in all packages. |
Struct fields are objects, which have access to their package. |
To expand: this rule is implemented in To implement this, we'd probably need to pass a |
Change https://go.dev/cl/422914 mentions this issue: |
Simplified reducer, for use as test case, and for the benefit of other readers: // file a.go
package a
type S struct{}
func (S) M() (_ struct{ f string }) {
return
} package b
import "./a"
type I interface {
M() (_ struct{ f string })
}
var _ I = a.S{} Similar to the original, the error message is:
The code compiles if the field As stated before, the compiler is correct to reject this code. |
Change https://go.dev/cl/452455 mentions this issue: |
For #54258. Change-Id: Ib0d326af2719bca1579f84c125f6573f87dce982 Reviewed-on: https://go-review.googlesource.com/c/go/+/452455 Run-TryBot: Robert Findley <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Robert Findley <[email protected]> Run-TryBot: Robert Griesemer <[email protected]>
For golang#54258. Change-Id: Ib0d326af2719bca1579f84c125f6573f87dce982 Reviewed-on: https://go-review.googlesource.com/c/go/+/452455 Run-TryBot: Robert Findley <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Robert Findley <[email protected]> Run-TryBot: Robert Griesemer <[email protected]>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
play/implementation:
What did you expect to see?
successful compilation or compilation error message indicating a problem. For example: "anonymous types in different packages"
What did you see instead?
self-contradictory error message:
The text was updated successfully, but these errors were encountered: