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

Match checking doesn't handle static constants correctly. #12501

Closed
eddyb opened this issue Feb 23, 2014 · 6 comments
Closed

Match checking doesn't handle static constants correctly. #12501

eddyb opened this issue Feb 23, 2014 · 6 comments
Labels
A-type-system Area: Type system

Comments

@eddyb
Copy link
Member

eddyb commented Feb 23, 2014

I would guess it doesn't go (properly) through const eval, causing weird errors like this one:

static MAX: uint = -1;
match 0 {
    1u..MAX => {}, // error: mismatched types in range
    _ => {}
}

If the value of MAX is changed to -1u, the code compiles, showing that match checking looks at the value of the static MAX but not at its type or computed value.

Further experimentation - using -1 as uint for MAX - produces this ICE:

error: internal compiler error: node_id_to_type: no type for node `expr -1 as uint (id=26)`
@eddyb
Copy link
Member Author

eddyb commented Mar 3, 2014

The ICE seems to have been fixed without mentioning this issue.
However, the original problem (with the initializer having a different type from the static itself) remains.

@pnkfelix
Copy link
Member

cc #23897

@pnkfelix
Copy link
Member

@eddyb I cannot reproduce the issue now; i.e. when I try (e.g. by plugging in mismatched types for the initializer, and also experimenting with using const vs static to see if that tickles something), I seem to consistently get a type check error.

can you make another example at this point demonstrating the issue here?

@pnkfelix
Copy link
Member

e.g. here is one version of updated code, but it compiles and runs (playpen):

#![feature(negate_unsigned)]

fn main() {
    const MAX: usize = -1;
    match 0 {
        1usize...MAX => {},
        _ => {}
    }
}

@eddyb
Copy link
Member Author

eddyb commented Apr 19, 2015

@pnkfelix it must have been fixed by adding more type information to const_eval, I guess.

@pnkfelix
Copy link
Member

closing, assumed fixed

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 25, 2022
internal: Update dashmap and freeze its version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants