Skip to content

go/types: int overflow in switch expression #11667

@dvyukov

Description

@dvyukov
Member

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

Activity

dvyukov

dvyukov commented on Jul 11, 2015

@dvyukov
MemberAuthor

The same happens in switch cases as well:

package a
func f() {
    switch 9223372036854775808 {
    case 9223372036854775808:
    }
}
added this to the Go1.6 milestone on Jul 11, 2015
griesemer

griesemer commented on Jul 11, 2015

@griesemer
Contributor

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.

gopherbot

gopherbot commented on Jul 27, 2015

@gopherbot
Contributor

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

changed the title [-]x/tools/go/types: int overflow in switch expression[/-] [+]go/types: int overflow in switch expression[/+] on Jul 31, 2015
locked and limited conversation to collaborators on Aug 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @dvyukov@griesemer@gopherbot

        Issue actions

          go/types: int overflow in switch expression · Issue #11667 · golang/go