Skip to content

Constants and expressions have diverged on enum-to-float casts. #8230

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

Closed
jld opened this issue Aug 2, 2013 · 3 comments
Closed

Constants and expressions have diverged on enum-to-float casts. #8230

jld opened this issue Aug 2, 2013 · 3 comments
Milestone

Comments

@jld
Copy link
Contributor

jld commented Aug 2, 2013

This program:

enum E { L0 = -1, H0 = 1 }
enum F { L1 = 1, H1 = 0xFFFFFFFFFFFFFFFF }
static C0: float = L0 as float;
static C1: float = H1 as float;
pub fn main() {
        println(fmt!("%?", L0 as float));
        println(fmt!("%?", C0));
        println(fmt!("%?", H1 as float));
        println(fmt!("%?", C1));
}

prints this (on x86_64):

-1
18446744073709552046
-1
18446744073709552046

This seems wrong. It would've been introduced by #8000, I think. Which of the two behaviors seen here is right?

@sanxiyn
Copy link
Member

sanxiyn commented Feb 3, 2014

Nominating.

@pnkfelix
Copy link
Member

pnkfelix commented Feb 6, 2014

P-backcompat-lang, 1.0.

@pnkfelix pnkfelix added this to the 1.0 milestone Feb 6, 2014
@hirschenberger
Copy link
Contributor

Updated example:

enum E { L0 = -1, H0 = 1 }
enum F { L1 = 1, H1 = 0xFFFFFFFFFFFFFFFF }
static C0: f32 = L0 as f32;
static C1: f32 = H1 as f32;
pub fn main() {
        println!("{:?}", L0 as f32);
        println!("{:?}", C0);
        println!("{:?}", H1 as f32);
        println!("{:?}", C1);
}

What's the desired behaviour?

bors added a commit that referenced this issue Jun 11, 2014
If this breaks your code, take a deep breath, go for a walk, and
consider why you're relying on the sign extension semantics of
enum-to-float casts.

[breaking-change]

Closes #8230.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants