golang / go

The Go programming language

Home Page:https://go.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go/types: int overflow in switch expression

dvyukov opened this issue · comments

gotype successfully compiles the following program:

package a
func f() {
    switch 9223372036854775808 {
    }
}

gc rejects it with:

go.go:3: constant 9223372036854775808 overflows int

gc seems to be right.

on commit af81789

The same happens in switch cases as well:

package a
func f() {
    switch 9223372036854775808 {
    case 9223372036854775808:
    }
}

The switch statement is actually underspecified in this respect. It does not say that the switch expression has to fit into a basic type. So technically, I believe gotype is correct. That said, I think the spec needs to be clarified as the current situation is not tenable in general. Leaving as go/types bug.

CL https://golang.org/cl/12713 mentions this issue.