-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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 in recorded types for instantiations #60212
Comments
Is the question here just what Type should be recorded in Info.Types for the Personally, I'm fine either way. Regardless of what
FWIW, I think golang.org/cl/492455 probably wouldn't have been necessary if As for the cases where |
Yes, I would argue that the |
At the moment (with pending CL 494116), we're close to what is being asked here, with the exception @mdempsky is pointing out:
|
Can you elaborate why? I understand and see the tension in the implicit instantiation case: there are two interesting types (uninstantiated and inferred instantiation), and only one of them can be recorded in Info.Types. But for explicit instantiations, I think the identifier should have the generic type and the IndexExpr/IndexListExpr should have the instantiated type. The index expression is the operation that transformed it from generic to instantiated type. It's not like |
Hmm, point taken about |
@findleyr Is there anything left to do here? |
If we now record the correct type for |
This issue describes what is arguably a bug in the
go/types
API, which we may or may not be able to fix.Specifically, consider the following generic declaration and instantiations:
In this example, we record in
types.Info.Types
the typefunc(int, string)
for the expressionsf[int]
andf[int, string]
, but for allf
identifiers we record the typefunc[P, Q any](P, Q)
.This is inconsistent, and in hindsight
clearlyprobably wrong:types.Info.Types
should record the effective type of each node in the syntax tree. In this case, theFun
expression of the call expression must have typefunc(int, string)
.types.Info.Types
should never contain generic types.There is some discussion of this at #47916 (comment), where I agreed with @mdempsky that it makes most sense to record the instance for the identifier. Unfortunately, that is not what was implemented, most likely as an artifact of the implementation. Mea culpa.
Now that new forms of inference are being implemented, it is harder to preserve this inconsistency. Can we fix this bug so that we record the instance for
f
, or must we preserve this behavior as a historical artifact?On the one hand, this bug has existed for over a year. On the other hand, the current behavior is inconsistent, and likely to cause bugs for tool authors.
CC @griesemer @mdempsky @adonovan @dominikh
The text was updated successfully, but these errors were encountered: