-
Notifications
You must be signed in to change notification settings - Fork 18k
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: inconsistency between LookupFieldOrMethod and NewMethodSet #60634
Comments
Side note: NewMethodSet is not used by the compiler (it doesn't exist in types2), so it's not surprising that there are inconsistencies. |
Thanks for digging into this crash! Yep, sounds like a bug in NewMethodSet. Since it has existed for a while, it's probably OK to defer the fix until 1.22 (but fixing it in 1.21 means that we can delete our workaround 6 months sooner...). |
Change https://go.dev/cl/501197 mentions this issue: |
Note that |
This change adds to x/tools a workaround for a bug in go/types that causes LookupFieldOrMethod and NewTypeSet to be inconsistent wrt an ill-typed method (*T).f where T itself is a pointer. The workaround is that, if Lookup fails, we walk the MethodSet. Updates golang/go#60634 Fixes golang/go#60628 Change-Id: I87caa2ae077e5cdfa40b65a2f52e261384c91167 Reviewed-on: https://go-review.googlesource.com/c/tools/+/501197 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Alan Donovan <adonovan@google.com> gopls-CI: kokoro <noreply+kokoro@google.com>
Change https://go.dev/cl/501299 mentions this issue: |
This change adds to x/tools a workaround for a bug in go/types that causes LookupFieldOrMethod and NewTypeSet to be inconsistent wrt an ill-typed method (*T).f where T itself is a pointer. The workaround is that, if Lookup fails, we walk the MethodSet. Updates golang/go#60634 Fixes golang/go#60628 Change-Id: I87caa2ae077e5cdfa40b65a2f52e261384c91167 Reviewed-on: https://go-review.googlesource.com/c/tools/+/501197 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Alan Donovan <adonovan@google.com> gopls-CI: kokoro <noreply+kokoro@google.com>
It is an error to declare a method on *T when T's underlying type is a pointer. Nonetheless, after reporting the error, the type checker must represent this situation. However, its representation is inconsistent: LookupFieldOrMethod fails to find the method, but NewMethodSet does report it. I think it should be an invariant that these two operations are consistent. (This bug was the cause of a crash in gopls.)
https://go.dev/play/p/uWoUFewDCj4:
Output:
@findleyr @mdempsky
The text was updated successfully, but these errors were encountered: