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

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

Closed
nikomatsakis opened this issue Aug 7, 2012 · 11 comments
Closed
Labels
A-codegen Area: Code generation I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@nikomatsakis
Copy link
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.

@catamorphism
Copy link
Contributor

This looks very similar to #2869

@catamorphism
Copy link
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
Copy link
Contributor

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

@graydon
Copy link
Contributor

graydon commented Dec 18, 2012

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

@pnkfelix
Copy link
Member

Not critical for 0.6; de-milestoning

@catamorphism
Copy link
Contributor

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

@graydon
Copy link
Contributor

graydon commented Jun 13, 2013

reproduced, and people run into it often, sure

@graydon
Copy link
Contributor

graydon commented Jun 13, 2013

accepted for production-ready milestone

@jasom
Copy link

jasom commented Jul 16, 2013

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

@pnkfelix
Copy link
Member

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

catamorphism added a commit to catamorphism/rust that referenced this issue Aug 8, 2013
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 rust-lang#3121
@msullivan
Copy link
Contributor

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

RalfJung pushed a commit to RalfJung/rust that referenced this issue Oct 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

6 participants