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

Open
mdempsky opened this issue Jul 26, 2019 · 0 comments
Open
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mdempsky
Copy link
Member

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
@julieqiu julieqiu added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants