Diagnose misplaced associated values in simple enum patterns

This commit is contained in:
Robert Widmann
2017-06-09 03:12:47 -07:00
parent 4504d76c2d
commit e50713d94e
4 changed files with 46 additions and 17 deletions

View File

@@ -27,9 +27,11 @@ func testE(e: E) {
break
case E.B<Int>(): // expected-error {{cannot specialize a non-generic definition}} expected-note {{while parsing this '<' as a type parameter bracket}}
break
case .C(): // FIXME: This should be rejected as well.
case .C(): // expected-error {{pattern with associated values does not match enum case 'C'}}
// expected-note@-1 {{remove associated values to make the pattern match}} {{10-12=}}
break
case .D(let payload): // FIXME: ditto.
case .D(let payload): // expected-error{{pattern with associated values does not match enum case 'D'}}
// expected-note@-1 {{remove associated values to make the pattern match}} {{10-23=}}
let _: () = payload
break
default:
@@ -37,10 +39,10 @@ func testE(e: E) {
}
guard
// Currently, these will be asserted in SILGen,
// or in no-assert build, verify-failed in IRGen
case .C() = e, // FIXME: Should be rejected.
case .D(let payload) = e // FIXME: ditto.
case .C() = e, // expected-error {{pattern with associated values does not match enum case 'C'}}
// expected-note@-1 {{remove associated values to make the pattern match}} {{12-14=}}
case .D(let payload) = e // expected-error {{pattern with associated values does not match enum case 'D'}}
// expected-note@-1 {{remove associated values to make the pattern match}} {{12-25=}}
else { return }
}
@@ -51,8 +53,10 @@ func canThrow() throws {
do {
try canThrow()
} catch E.A() { // FIXME: Should be rejected.
} catch E.A() { // expected-error {{pattern with associated values does not match enum case 'A'}}
// expected-note@-1 {{remove associated values to make the pattern match}} {{12-14=}}
// ..
} catch E.B(let payload) { // FIXME: ditto.
} catch E.B(let payload) { // expected-error {{pattern with associated values does not match enum case 'B'}}
// expected-note@-1 {{remove associated values to make the pattern match}} {{12-25=}}
let _: () = payload
}