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

go/constant: panic in Int64Val #13771

Closed
alandonovan opened this issue Dec 29, 2015 · 3 comments
Closed

go/constant: panic in Int64Val #13771

alandonovan opened this issue Dec 29, 2015 · 3 comments
Milestone

Comments

@alandonovan
Copy link
Contributor

This program panics when built and run with a tip Go distribution:

http://play.golang.org/p/AOMz-2Sduz

    million := constant.MakeFromLiteral("1e6", token.FLOAT, 0)
    constant.Int64Val(million) // panic: 1000000 (constant.ratVal) not an Int

It works under Go 1.5.

@gopherbot
Copy link

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

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Dec 29, 2015
@griesemer
Copy link
Contributor

Working as intended.

With the go/constant semantic change you need to call ToInt first:

package main

import (
    "go/constant"
    "go/token"
)

func main() {
    million := constant.MakeFromLiteral("1e6", token.FLOAT, 0)
    million = constant.ToInt(million)
    x, ok := constant.Int64Val(million) // panic: 1000000 (constant.ratVal) not an Int
    println(x, ok)
}

works fine.

@alandonovan
Copy link
Contributor Author

Of course. Sorry for the noise.

@golang golang locked and limited conversation to collaborators Jan 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants