Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upMissing "unreachable pattern" error with range #27005
Comments
Aatch
added
the
I-papercut
label
Jul 13, 2015
This comment has been minimized.
This comment has been minimized.
|
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
added
P-low
A-typesystem
labels
Jan 12, 2017
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis says not a bug. |
eefriedman commentedJul 13, 2015
Currently compiles, but the
'a'...'b'pattern is clearly unreachable.