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

Wrong matching with enums and overlapping ranges #13867

Closed
seanmonstar opened this issue Apr 30, 2014 · 5 comments · Fixed by #13940
Closed

Wrong matching with enums and overlapping ranges #13867

seanmonstar opened this issue Apr 30, 2014 · 5 comments · Fixed by #13940
Labels
A-codegen Area: Code generation

Comments

@seanmonstar
Copy link
Contributor

#[deriving(Show)]
enum State {
    AtoZ(uint),
    Numeric,
}


fn main() {
    let state = Numeric;
    let b = 97u8; // a
    let r = match (state, b as char) {
        (AtoZ(..), 'a'..'z') => {
            "Named"
        },

        (Numeric, 'x') => {
            "Hex"
        },


        _ => {
            "Other"
        }
    };
    println!("{} {}: {}", state, b as char, r);
}

Outputs Numeric a: Hex. Clearly, a shouldn't match x.

Worth noting: if you change the first range to not include x, such as a..w, it works correctly. Also, removing the field from AtoZ also makes the match work correctly.

@seanmonstar
Copy link
Contributor Author

blocking #13831

@lilyball
Copy link
Contributor

lilyball commented May 2, 2014

cc me

@edwardw
Copy link
Contributor

edwardw commented May 2, 2014

This seems to be a regression introduced by #13034.

@lilyball
Copy link
Contributor

lilyball commented May 2, 2014

This is impacting #13896 as well. I had to add in guards that re-test the range to work around it.

@edwardw
Copy link
Contributor

edwardw commented May 2, 2014

The defect of #13034 is that it doesn't check multiple refutable patterns, which is exactly what this bug report is about.

edwardw added a commit to edwardw/rust that referenced this issue May 5, 2014
It has been found that rust-lang#13034 was flawed and caused regression rust-lang#13867.
This patch reveres the changes made by it except the companion tests.
edwardw added a commit to edwardw/rust that referenced this issue May 5, 2014
By carefully distinguishing falling back to the default arm from moving
on to the next pattern, this patch adjusts the codegen logic for range
and guarded arms of pattern matching expression. It is a more
appropriate way of fixing rust-lang#12582 and rust-lang#13027 without causing regressions
such as rust-lang#13867.

Closes rust-lang#13867
bors added a commit that referenced this issue May 6, 2014
By carefully distinguishing falling back to the default arm from moving
on to the next pattern, this patch adjusts the codegen logic for range
and guarded arms of pattern matching expression. It is a more
appropriate way of fixing #12582 and #13027 without causing regressions
such as #13867.
    
Closes #13867
arcnmx pushed a commit to arcnmx/rust that referenced this issue Jan 9, 2023
Fallback to invisible associated functions and constants if no visible resolutions are found

Still lacking tests, will add those later
Fixes rust-lang/rust-analyzer#13126
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants