Skip to content

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

@mdempsky

Description

@mdempsky

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions