-
Notifications
You must be signed in to change notification settings - Fork 18k
go/types,x/tools/go/packages: types.Implements() fails for interfaces with named types #61412
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
Comments
(attn @griesemer @findleyr) |
This is working as expected. Note that Here is your example, a bit further simplified so I could see what's going on (in general when sending a repro case, please minimize by removing all unnecessary code - it greatly helps us diagnosing problems). The problem is that you are loading the same packages twice ( The type-identity properties should be better documented. I filed #61418. Closing as working as intended. |
PS: Here is your code with the respective correction: playground. |
Thank you for the quick reply and help - that is much appreciated! That is not ideal (e.g. the interface could be defined in a completely different place than the code I am trying to analyse against it). I wonder if this could be resolved by having the "identity" defined in a more deterministic way. I do, however, appreciate that that's the imitation of the current toolset (which I did not appreciate earlier), so nothing more to do here :-). Thank you once again for your help! |
Problem summary
It seems like the function
types.Implements
will fail if theInterface
provided contains methods returning custom types (even if everything is defined in the exact same package).Sample minimal code can be found here:
go.dev/play
(go executable is not directly available), needs to be copy-pasted.Details
Specifically, given the below which compiles fine (note the assertion that the struct "something" implements both interfaces):
the check
types.Implements(types.NewPointer(typesObj.Type()), interfaceSearched)
will return true only for MySimplerInterface, where the types details have been loaded usinggo/packages
What version of Go are you using (
go version
)?go1.20.5
What operating system and processor architecture are you using (
go env
)?darwin / arm64
The text was updated successfully, but these errors were encountered: