Skip to content

C-like tags should be castable to int with or without custom discriminants #1511

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
nikomatsakis opened this issue Jan 13, 2012 · 2 comments · May be fixed by 47-studio-org/rust#6
Closed

C-like tags should be castable to int with or without custom discriminants #1511

nikomatsakis opened this issue Jan 13, 2012 · 2 comments · May be fixed by 47-studio-org/rust#6

Comments

@nikomatsakis
Copy link
Contributor

This type checks (tag-disr-val-shape.rs):

enum color {
    red = 0;
    green = 1;
    blue = 2;
    black = 3;
    white = 4;
}

fn main() {
    assert uint::to_str(red as uint, 10u) == #fmt["%?", red];
    assert uint::to_str(green as uint, 10u) == #fmt["%?", green];
    assert uint::to_str(white as uint, 10u) == #fmt["%?", white];
}

but this does not (tag-auto-disr-val-shape.rs):

enum color { red; green; blue; black; white; }

fn main() {
    assert (uint::to_str(red as uint, 10) == #fmt["%?", red]);
    assert (uint::to_str(green as uint, 10) == #fmt["%?", green]);
    assert (uint::to_str(white as uint, 10) == #fmt["%?", white]);
}

However, the two programs are equivalent but for the fact that in one case the discriminants were automatically assigned.

When fixing this bug, please remove the xfail-test directives from those two test files!

@kevina
Copy link
Contributor

kevina commented Jan 13, 2012

You have a bug in tag-auto-disr-val-shape.rs, change the 10 to 10u and it should compile.

Let me know if it doesn't work for you.

@nikomatsakis
Copy link
Contributor Author

never mind, the bug is in the pretty printer, which sometimes prints out 10u as 10

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.

2 participants