I'm not sure if this has ever worked, but I'd say it's definitely bug-worthy. I ran a quick test and which cases are allowed appears to depend on their declaration order in the enum.
Pretty wired. Actually pattern match allow labels but only the last one case pattern allowed.
enum E
{
case P(s:String)
case P(i:Int)
case P(b:Bool) //only this - the last case can be matched and also be labelled matched
}
/* labelled pattern match */
if case let E.P(b:q)=E.P(b:true) {print(q)}
//label `b` is allowed and print `true` - pattern matched
if case let E.P(s:q)=E.P(s:"blah") {print(q)}
//error: `Tuple pattern element label 's' must be 'b'`
if case let E.P(i:q)=E.P(i:123) {print(q)}
//error: `Tuple pattern element label 'i' must be 'b'`
/* unlabelled pattern match */
if case let E.P(q)=E.P(b:true) {print(q)}
//print `true` - pattern matched
if case let E.P(q)=E.P(s:"blah") {print(q)}
//print nothing - pattern unmatched
if case let E.P(q)=E.P(i:123) {print(q)}
//print nothing - pattern unmatched
Q:
1.Why only the last pattern case with label E.P(b:) is allowed in pattern match if statement? Others compile error...
2.Why only the last pattern case E.P(b:) can be matched? Others compiles but unmatched...