assertion failure in trans_alt when combining if, nested patterns #3121

Closed
nikomatsakis opened this Issue Aug 7, 2012 · 11 comments

Projects

None yet

6 participants

Contributor

The following test:

enum side { mayo, catsup, vinegar }
enum order { hamburger, fries(side), shake }
enum meal { to_go(order), for_here(order) }

fn foo(m: @meal, cond: bool) {
    match *m {
      to_go(_) => { }
      for_here(_) if cond => {}
      for_here(hamburger) => {}
      for_here(fries(s)) => {}
      for_here(shake) => {}
    }
}

fn main() {
    foo(@for_here(hamburger), true)
}

results in an assertion failure in trans:

;RUST_LOG=rustc=0 rustc ~/tmp/pat-bug-in-trans.rs 
rust: task failed at 'Assertion m.len() > 0u || is_some(chk) failed', /Users/nmatsakis/versioned/rust-gold/src/rustc/middle/trans/alt.rs:431
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=0,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues
rust: task failed at 'explicit failure', /Users/nmatsakis/versioned/rust-gold/src/rustc/driver/rustc.rs:264
rust: domain main @0x7f8d99800010 root task failed
rust: task failed at 'killed', /Users/nmatsakis/versioned/rust-gold/src/libcore/task.rs:520

The problem has to do with the if, something in the logic there gets a bit confused.

Contributor

This looks very similar to #2869

Contributor

I have a fix for this; running tests. Basically, enter_default needs to know whether a pattern has a guard, and not consider a guarded pattern to be a default.

@catamorphism catamorphism was assigned Dec 8, 2012
Contributor

Oops, it's not as simple as that. Still working on it.

Contributor
graydon commented Dec 18, 2012

Bumping this since it can always be worked around. Should fix but non blocking.

Member

Not critical for 0.6; de-milestoning

Contributor

Nominating for milestone 5, production-ready. I have an old branch that partially fixes it, but it needs more work.

Contributor
graydon commented Jun 13, 2013

reproduced, and people run into it often, sure

Contributor
graydon commented Jun 13, 2013

accepted for production-ready milestone

jasom commented Jul 16, 2013

Is this fixed in 0.7? I think I've run into it recently. Is there a workaround?

Member

@jasom: combine the caes with the same patterns, moving their ifs to the right-hand side of the pattern?

@catamorphism catamorphism added a commit to catamorphism/rust that referenced this issue Aug 8, 2013
@catamorphism catamorphism Don't treat guarded patterns as default patterns
There were several open issues that were all manifestations
of the same bug in trans::alt. The fix is for enter_default
to avoid treating any pattern with a guard as a default.

I judged this change too minor for code review, but someone tell
me if I'm wrong :-)

Closes #3121
25e487d
Contributor

I think I have a pretty good idea of how to fix this, although it seems a little subtle/hacky.

@msullivan msullivan closed this in 437a4c2 Aug 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment