Sema: Let .foo patterns fall back to being ExprPatterns if they don't match an enum case.

This lets you match `case .foo` when `foo` resolves to any static member, instead of only a `case`, albeit without the exhaustiveness checking and subpattern capabilities of proper cases. While we're here, adjust the type system we set up for unresolved patterns embedded in expressions so that we give better signal in the error messages too.
This commit is contained in:
Joe Groff
2017-02-28 21:51:39 -08:00
parent 17da6b38de
commit fc16cb5dda
10 changed files with 123 additions and 25 deletions

View File

@@ -100,7 +100,7 @@ enum Voluntary<T> : Equatable {
}
switch foo {
case .Naught: // expected-error{{enum case 'Naught' not found in type 'Foo'}}
case .Naught: // expected-error{{pattern cannot match values of type 'Foo'}}
()
case .A, .B, .C:
()
@@ -137,7 +137,7 @@ case .Twain,
var notAnEnum = 0
switch notAnEnum {
case .Foo: // expected-error{{enum case 'Foo' not found in type 'Int'}}
case .Foo: // expected-error{{pattern cannot match values of type 'Int'}}
()
}
@@ -264,10 +264,8 @@ case +++(_, var d, 3):
// expected-error@-1{{'+++' is not a prefix unary operator}}
()
case (_, var e, 3) +++ (1, 2, 3):
// expected-error@-1{{binary operator '+++' cannot be applied to operands of type '(_, <<error type>>, Int)' and '(Int, Int, Int)'}}
// expected-note@-2{{expected an argument list of type '((Int, Int, Int), (Int, Int, Int))'}}
// expected-error@-3{{'var' binding pattern cannot appear in an expression}}
// expected-error@-4{{'var' binding pattern cannot appear in an expression}}
// expected-error@-1{{'_' can only appear in a pattern}}
// expected-error@-2{{'var' binding pattern cannot appear in an expression}}
()
}