-
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
cmd/compile: out of range integer in range loop crashes the compiler #65133
Comments
cc @golang/compiler |
Related: #62466 types2 leaves |
Just checked golang.org/x/tools/go/ssa and it just lets the integer silenty overflow, without error. Should I report that as a separate bug? (It does appear to use a signed integer though). EDIT: looks more like a bug in go/types, because |
Change https://go.dev/cl/556295 mentions this issue: |
Thanks for reporting. This is both a bug in the type checkers and an issue with the spec. In fact there are more issues here. See #65137. |
Change https://go.dev/cl/556398 mentions this issue: |
Add missing checks for the case where the range expression is a (possibly untyped) constant integer expression. Add context parameter to assignVar for better error message where the expression is part of a range clause. Also, rename s/expr/Expr/ where it denotes an AST expression, for clarity. Fixes golang#65133. For golang#65137. Change-Id: I72962d76741abe79f613e251f7b060e99261d3ae Reviewed-on: https://go-review.googlesource.com/c/go/+/556398 Run-TryBot: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
Go version
go version devel go1.22-8e658eee9c Wed Jan 17 03:56:30 2024 +0000 linux/arm64
Output of
go env
in your module/workspace:What did you do?
I ran the following program in Go 1.22 (tip):
On the Playground: https://go.dev/play/p/MCs2ntWII_I?v=gotip
What did you see happen?
The compiler crashes with the following stack trace:
What did you expect to see?
This code should probably show a regular compiler error because the integer is out of range.
This is what the specification says:
This doesn't explicitly say which type should be used for untyped integers. My assumption would be that it would be the same as this for example:
...meaning that it would default to
int
(notuint
as the stack trace suggests).uint
would also seem reasonable to me for range loops, which would be a bit inconsistent but would make sense for range loops.In fact, the following code does compile, but I'm not sure it should (it is out of range for
int
):The text was updated successfully, but these errors were encountered: