-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: valid string(1<<s) is not accepted #21981
Comments
Change https://golang.org/cl/65370 mentions this issue: |
Under certain circumstances involving shifts, go/types didn't verify that untyped constant values were representable by the relevant type, leading to the acceptance of incorrect programs (see the issue). Fixing this code exposed another problem with int-to-string conversions which suddenly failed because now the type-checker complained that a (constant) integer argument wasn't representable as a string. Fixed that as well. Added many additional tests covering the various scenarious. Found two cmd/compile bugs in the process (#21979, #21981) and filed a go/types TODO (#21982). Fixes #21727. Change-Id: If443ee0230979cd7d45d2fc669e623648caa70da Reviewed-on: https://go-review.googlesource.com/65370 Reviewed-by: Alan Donovan <adonovan@google.com>
It's not obvious to me that the error is wrong. If I realize integer-to-string conversion is a different kind of conversion than integer-to-complex, but I can't immediately spot any spec wording that suggests this distinction is relevant here. |
This is indeed not an error; in fact go/types is wrong. See #26096. |
https://play.golang.org/p/iS44hmBD5n
produces
tmp/sandbox014611473/main.go:5:12: invalid operation: 1 << s (shift of type string)
which is clearly wrong. The program should compile and run.
The text was updated successfully, but these errors were encountered: