You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to do types.Type assignable checks with types from different golang.org/x/tools/go/packages.Load calls but they don't work as I'd expect. Here is an example to reproduce:
My actual use-case is a little more complex with with parsing multiple different packages and then comparing types between them mainly with types.AssignableTo which uses types.Identical.
I could load all all my packages in one golang.org/x/tools/go/packages.Load call, but this would make my application more complex and I think the current behavior of go/types.Identical isn't obvious when using it.
What did you expect to see?
go/types.Identical should return true when supplying the same types. Even if the types are from different packages.Load calls.
What did you see instead?
The string representation is the same but the types aren't identical.
one = jmattheis/issue.Input
two = jmattheis/issue.Input
identical = false
The call to indenticalOrigin(x, y) inside predicates.go returns false.
The text was updated successfully, but these errors were encountered:
This is working as intended, according to the design of go/types, though I am sympathetic to the difficulties it causes and we have talked about changing it. It would be more flexible if any pair of Types could be compared, and if the packages of any named types within them were considered equal if they have the same Package.Path string; see #57497.
We could also improve the documentation; see #53914.
Go version
go version go1.21.4 linux/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
I'm trying to do
types.Type
assignable checks with types from differentgolang.org/x/tools/go/packages.Load
calls but they don't work as I'd expect. Here is an example to reproduce:My actual use-case is a little more complex with with parsing multiple different packages and then comparing types between them mainly with
types.AssignableTo
which usestypes.Identical
.I could load all all my packages in one
golang.org/x/tools/go/packages.Load
call, but this would make my application more complex and I think the current behavior ofgo/types.Identical
isn't obvious when using it.What did you expect to see?
go/types.Identical
should returntrue
when supplying the same types. Even if the types are from differentpackages.Load
calls.What did you see instead?
The string representation is the same but the types aren't identical.
The call to
indenticalOrigin(x, y)
insidepredicates.go
returnsfalse
.The text was updated successfully, but these errors were encountered: