-
Notifications
You must be signed in to change notification settings - Fork 18k
go/types: untyped int literal is identified as uint in go1.17 #47243
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
This at least conform to the spec:
|
This is a consequence of CL 291316 -- bisected to confirm.
Shifts are particularly tricky with respect to type conversion. In this case, I think it might be ambiguous in the spec. Consider the full quote (emphasis mine):
Per my reading of this, it's not specified what happens to the type of the right operand. |
For this case, the spec only requires that the untyped RHS constant be representable by a value of type For comparison, in the section on Index expressions where we have similar requirements on constant indices, the spec states explicitly that "a constant index must be non-negative and representable by a value of type int" and "a constant index that is untyped is given type int". The same is true for However, the "a constant index that is untyped is given type int" phrase is missing in the section on Slice expressions, yet Finally, in the section on Array types, the spec only requires representability but doesn't assign a type, and The "is given type int" part is relevant in context and decides what type is given to other untyped expressions, such as shifts. For more examples, see this expanded test. The The spec should probably apply the same rules for slice expression indices as for ordinary index expressions. |
Change https://golang.org/cl/336912 mentions this issue: |
CC @golang/release I marked this issue as a release blocker. It would be good to fix it for 1.17, and we can probably merge a fix today or tomorrow. Please let me know if this causes disruptions to the release, or if there's anything else we should do. |
Change https://golang.org/cl/337529 mentions this issue: |
Change https://golang.org/cl/338195 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
the issue is different behaviour between go1.17 and go1.16
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
in go1.17 go/types identifies the literal 3 as uint, while go1.16 reports an untyped int kind.
see:
https://play.golang.org/p/WuuJ6PGlylQ
What did you expect to see?
Go1.16 (and the playground) shows:
What did you see instead?
Go1.17 shows:
Is this kind of change in go/types considered as a bug?
The text was updated successfully, but these errors were encountered: