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

Enum variant type not type checked in pattern matching if the pattern contains variables #6286

Open
ironcev opened this issue Jul 20, 2024 · 1 comment
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged

Comments

@ironcev
Copy link
Member

ironcev commented Jul 20, 2024

When an enum variant match pattern contains variables, the variant type used within the pattern is not checked against the enum variant type. E.g, this compiles:

script;

enum E {
    A: (u8, u8, u8),
}

fn main() {
    let e = E::A((0, 0, 0));
    let _ = match e {
        E::A(_) => {},
        E::A(_, _) => {},
        E::A(_, _, _) => {},
        E::A(_, _, _, _) => {},
        E::A(x) => {},
        E::A(x, x) => {},
        E::A(x, x, x) => {},
        E::A(x, x, x, x) => {},
    };
}

If the pattern does not contain variables, errors will be properly reported. E.g., this emits expected type mismatch errors:

    let e = E::A((0, 0, 0));
    let _ = match e {
        E::A(0) => {},
        E::A(0, 0) => {},
        E::A(0, 0, 0) => {},
    };

But as soon as we have variables, type mismatching is not checked. E.g., this compiles without errors:

    let e = E::A((0, 0, 0));
    let _ = match e {
        E::A(x, 0) => {},
        E::A(x, 0, 0) => {},
    };
@ironcev ironcev added bug Something isn't working compiler General compiler. Should eventually become more specific as the issue is triaged compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Jul 20, 2024
@ironcev
Copy link
Member Author

ironcev commented Jul 20, 2024

Related to #5417.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

No branches or pull requests

1 participant