-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: go/types: assign non-untyped types for all runtime expressions #62466
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
Many constant expressions only have "untyped" types. For example, In other cases, a constant expression is used in a context that implies a "true" (runtime) type. For example (Aside: I vaguely recall requesting this behavior a long time ago, but have since come to regret doing so as it makes it harder when analyzing typed syntax to notice implicit conversions. At least prior to generics, there were very few places where type information flowed top-down: only shifts, IIRC.) So I'm not sure exactly what change this issue is asking for. |
I think a better way to state my request would be that go/types should only assign "untyped" types to constant expressions. Any non-constant expression should have an assigned non-untyped type. The linked to code mentions several cases where go/types assigns "untyped" types to non-constant expressions: go/src/cmd/compile/internal/noder/helpers.go Lines 100 to 111 in b637211
|
Oh, just hedging my proposals I suppose. |
I think this is fine and I was planning to do this, a few years in the past, if I recall correctly. But we ended up not doing it because (I'm not sure anymore) some backward-compatibility or other issues. We should perhaps try again, and if need be introduce a flag to control the behavior. |
Compilers like cmd/compile and x/tools/go/ssa prefer to work exclusively with true types, but there are several cases where go/types leaves expressions as untyped:
go/src/cmd/compile/internal/noder/helpers.go
Line 89 in b637211
It would be convenient if go/types were to provide appropriate true types for each of these contexts, since it's already having to check that the untyped expressions are suitable.
Related: #47151 proposes adding a second map for the implicitly converted type of expressions. I'd suggest that's a reasonable way to avoid breaking users that expect the current untyped types (e.g., #47243).
/cc @griesemer @findleyr @alandonovan
The text was updated successfully, but these errors were encountered: