-
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
spec: shift string(1 << s) should be invalid #45114
Comments
cc: @findleyr |
My vote is to change the spec, since cmd/compile, gccgo, and GoLLVM all reject this. I'm assuming that nobody is clamoring for this to work. |
Fair enough. If anything, we need to clarify the spec in that regard. |
Change https://golang.org/cl/303094 mentions this issue: |
Temporarily disable a questionable test case in fixedbugs/bug193.go and enable the test as a whole. See the issues below for details. Updates #45114. Updates #45117. Change-Id: I1de6f8d79b592eeeec139cd92b6c9cac56a9a74b Reviewed-on: https://go-review.googlesource.com/c/go/+/303094 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Change https://golang.org/cl/379256 mentions this issue: |
See #45117 for the implementation issue. |
For #45114. Fixes #45117. Change-Id: I71d6650ae2c4c06952fce19959120f15f13c08a2 Reviewed-on: https://go-review.googlesource.com/c/go/+/379256 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Change https://golang.org/cl/379275 mentions this issue: |
For golang#45114. Fixes golang#45117. Change-Id: I71d6650ae2c4c06952fce19959120f15f13c08a2 Reviewed-on: https://go-review.googlesource.com/c/go/+/379256 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Fixes golang#45114. Change-Id: I969e5f1037254fc0ffbba2fc07a81a3987e6b05f Reviewed-on: https://go-review.googlesource.com/c/go/+/379275 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
is not accepted by the compiler:
Per the spec (https://golang.org/ref/spec#Constant_expressions):
"If the left operand of a non-constant shift expression is an untyped constant, it is first implicitly converted to the type it would assume if the shift expression were replaced by its left operand alone."
In this case, the left operand would be converted to
int
(not string). This is different from cases such as, sayfloat64(1 << s)
where1
is implicitly converted to1.0
because it can be done without loss of precision. It seems a bit far-fetched to claim that a1
can be converted to a string without loss of precision. (That said, the spec is notoriously difficult to decipher with respect to shifts and implicit conversions.)As an aside, there's still #3939 which is proposing to prohibit
string(int_value)
, andgo vet
is checking for this. So we're not permitting a new category of programs by makingstring(1 << s)
valid.Both
go/types
andtypes2
accept this code.The test
$GOROOT/test/fixedbugs/bug193.go
assumes that this code should fail.The text was updated successfully, but these errors were encountered: