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

Compiler gives wrong error message when matching on invalid enum value #10503

Closed
orenbenkiki opened this issue Nov 15, 2013 · 2 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@orenbenkiki
Copy link

Trying to compile the following code:

enum Foo { Bar, Baz }
fn bug(foo: Foo) {
    match (foo, foo) {
      (Bar, Bar) => {},
      (Bar, Bug) => {},
      (Bar, Baz) => {},
    }
}

I get the error message:

..........:6:6: 6:16 error: unreachable pattern
..........:6       (Bar, Baz) => {},
                   ^~~~~~~~~~

Instead of an error message complaining that Bug isn't a valid value for the matched enum (in fact, it isn't even defined anywhere). The error message doesn't even point at the line containing the bad value - it took me a while to figure out what was going on.

@huonw
Copy link
Member

huonw commented Nov 15, 2013

This is because the compiler takes (Bar, Bug) to be creating a new variable Bug bound to the second field of the tuple, i.e. same as (Bar, a). I'm inclined to close this as a dupe of #10304.

@huonw
Copy link
Member

huonw commented Nov 15, 2013

Hm, #10402 is also similar, so I think this is covered by the combination of those two. Closing.

@huonw huonw closed this as completed Nov 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

2 participants