Skip to content

Wrong matching with enums and overlapping ranges #13867

Closed
@seanmonstar

Description

@seanmonstar
#[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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions