-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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/ast,go/parser: Decl field of type parameter identifier is nil for methods (but not for functions) #50956
Comments
Thank you. No, this is not intentional. See also #45221, which may have missed methods. Will try to fix for 1.18 (but not marking as a release blocker as we are trying to be very selective about release blockers at this point. CC @griesemer |
Change https://golang.org/cl/382247 mentions this issue: |
I recalled incorrectly: as commented here we didn't resolve receiver type parameters because we weren't sure how to declare them: the docmentation for In general, syntactic object resolution is unreliable (it can be incorrect), slow, and of questionable value -- tools that need object resolution should probably use @griesemer and I discussed this today and think we should consider this for 1.19, but probably shouldn't do anything for 1.18 at this point. One thing that occurred to me, however, is that we could/should avoid incorrect object resolution involving type parameters. For example:
In this example, because we don't declare the type parameter |
@findleyr Fixing the incorrect resolution for 1.18 seems fine, if it is easy (which I think it might be). But if it's anything more than that, it's ok to defer at this point. We're veryclose to the release and object resolution is not a feature that we recommend using in the first place. We won't fix everything for 1.18 and this is certainly low priority. |
Shouldn't this be documented somewhere? go/ast doesn't say anything about this and go/parser just documents the existence of SkipObjectResolution. |
We should document this, however I think maybe we overstated a bit: I saw your CL and godoc is one place where syntactic object resolution makes sense and should generally work. I am not sure that it is 100% obvious that changing godoc to use go/types is a good change, as the performance implications are significant and imprecision is acceptable. Unfortunately, at this point it is really too late to add a new |
No, I think it's a good decision. |
Declare receiver type parameters in the function scope, but don't resolve them (for now), as ast.Object.Decl is not documented to hold *ast.Idents. This avoids incorrect resolution of identifiers to names outside the function scope. Also make tracing and error reporting more consistent. For #50956 Change-Id: I8cd61dd25f4c0f6b974221599b00e23d8da206a1 Reviewed-on: https://go-review.googlesource.com/c/go/+/382247 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
@griesemer @findleyr This is the 1.19 milestone. Move to 1.20? To Backlog? Thanks. |
Let's move to 1.20; we may or not do this depending on the outcome of #52463 |
@findleyr What's the status of this issue? Given that object resolution is now deprecated, is there anything we should be doing here? Should this move to 1.23? |
due to golang/go#50956 I must to drop check for typeParams (which is `nil` for methods). So from now on, i am checking if param is interface implementation, then exclude one by one interface types. Added new tests. closes #37
* dev: Fix for missing TypeParams in methods due to golang/go#50956 I must to drop check for typeParams (which is `nil` for methods). So from now on, i am checking if param is interface implementation, then exclude one by one interface types. - Added new tests. - Added compatibility code (to align with go1.18 and go1.19 type params representation) closes #37
See: https://gotipplay.golang.org/p/QhA7oB1-h54
For
F
, a generic funciton, the identifierT
has a Decl field referring to the field in the type parameter list ofF
.But for
M
, a method for a generic type, the identifier
T` has a nil Decl field instead.Is this intentional? Seems inconsistent.
cc @findleyr
The text was updated successfully, but these errors were encountered: