Skip to content
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: constant LHS in non-constant shift used as index expression must fit into int #22969

griesemer opened this issue Dec 1, 2017 · 2 comments


Copy link

@griesemer griesemer commented Dec 1, 2017

Per the spec, the following code

var a []int
var s uint
var _ = a[0xffffffffffffffff << s]

is not permitted:

  • the type of an untyped LHS in a non-constant shift is the type it would have without the shift
  • the type of an untyped constant index must be non-negative and representable by a value of type int

Here, 0xffffffffffffffff does not fit into an int, but go/types accepts it.

cmd/compile reports: constant 18446744073709551615 overflows int

@griesemer griesemer added this to the Go1.11 milestone Dec 1, 2017
@griesemer griesemer self-assigned this Dec 1, 2017
Copy link
Contributor Author

@griesemer griesemer commented Dec 1, 2017

Not urgent but the fix may be simple in which case we may want to do it for Go1.10.


@ianlancetaylor ianlancetaylor removed this from the Go1.11 milestone Jun 29, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Jun 29, 2018
Copy link

@gopherbot gopherbot commented Oct 24, 2018

Change mentions this issue: go/types: untyped shifted constants must fit their expected int type


@gopherbot gopherbot closed this in 9f7b1a8 Oct 24, 2018
@golang golang locked and limited conversation to collaborators Oct 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants