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

Missing "unreachable pattern" error with range #27005

Closed
eefriedman opened this Issue Jul 13, 2015 · 2 comments

Comments

Projects
None yet
3 participants
@eefriedman
Copy link
Contributor

eefriedman commented Jul 13, 2015

fn main() {
    match 'a' {
        'a' => {}
        'b' => {}
        'a'...'b' => {}
        _ => {}
    }
}

Currently compiles, but the 'a'...'b' pattern is clearly unreachable.

@Aatch Aatch added the I-papercut label Jul 13, 2015

@Aatch

This comment has been minimized.

Copy link
Contributor

Aatch commented Jul 13, 2015

I looked into this, and I'm not sure it's possible to fix without a massive amount of work. Basically, we check for unreachable patterns by seeing if a pattern is still "useful" by the time we get to it. We determine whether or not it's useful by specialising as we go down. The way the code is written right now means you can't create new patterns or modify existing ones, so we can't modify or split the range pattern during specialisation.

Ideally we should be able to do something like this (modified to be a bit more explanatory):

match 'a' {
  'a' => { }
  'c' => { }
  'a'...'e' => { }
  _ => { }
}
// Specialize for the first arm
if 'a' == 'a' { } else {
  match 'a' {
    'c' => { }
    'b'...'e' => { } // Modified range to account for != 'a'
    _ => { }
  }
}
// specialize for the next arm
if 'a' == 'a' { } 
else if 'a' == 'c' { }
else {
    match 'a' {
    'b'...'b' | 'd'...'e' => { } // split range to account for !='c'
    _ => { }
  }
}
// And so on...

However, doing so will require a signfiicant amount of work in the relevant part of the compiler.

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jan 12, 2017

@nikomatsakis says not a bug.

@brson brson closed this Jan 12, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.