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

gccgo: bad "incompatible types" error when comparing untyped expressions #33306

mdempsky opened this issue Jul 26, 2019 · 0 comments


Copy link

commented Jul 26, 2019

gccgo incorrectly reports error: incompatible types in binary expression for this test program:

package main

func main() {
        var v uint = 32
        println(1 << v == '\002' << v)

The Go spec says:

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.

So 1 and '\002' should take on the types that they would in the comparison 1 == '\002', which is rune/int32.

For comparison, the program prints true when compiled with cmd/compile, and it type checks with go/types.

/cc @ianlancetaylor

@mdempsky mdempsky added this to the Gccgo milestone Jul 26, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.