Skip to content

[ .. a] pattern breaks matches #6909

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

Closed
huonw opened this issue Jun 3, 2013 · 5 comments
Closed

[ .. a] pattern breaks matches #6909

huonw opened this issue Jun 3, 2013 · 5 comments
Labels
A-codegen Area: Code generation

Comments

@huonw
Copy link
Member

huonw commented Jun 3, 2013

This should print ok, but prints not ok.

fn main() {
    println(match &[1] {
        [2, .. _] => "not ok",
        [.. _]  => "ok"
    });
}

The problem seems to be the [.. _] pattern, since if this is replaced by _ or a, it prints ok. It also prints ok when matching on an empty vector. (The use of _ is not important.)

@msullivan
Copy link
Contributor

Confirmed. Bugs where we actually generate the wrong code are pretty bad, so fixing this is probably decently high priority. Not sure it actually fits for a milestone, though?

@msullivan
Copy link
Contributor

OK, I've figured out what is going on. The problem is that the matcher is too strict when deciding what patterns are included in some condition. Essentially the problem is that it decides that the condition that are relevant are "length > 1" and "length > 0" and decides that [2, .. _] is the only pattern that matches "length > 1", which is obviously bogus. Fixing this seems a bit tricky, since we need to be able to properly expand out the patterns while still properly handling bindings.

Note that this seems like a degenerate case, since the last pattern could just be replaced with a _, but there are more complicated and interesting things where this happens too.

@msullivan
Copy link
Contributor

Oh, no, there is a pretty simple solution to this. The trick is, when checking submatches generated by a vector length check, set it up so that if none of the subpatterns match, it goes to the next vector length check. I'm explaining it poorly, but it is a really simple fix.

@msullivan
Copy link
Contributor

Simple fix has problems, though. So have a more complex fix. Which also has problems. Still investigating.

@msullivan
Copy link
Contributor

OK, have it all fixed. Just trying to document it well at this point.

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

No branches or pull requests

2 participants