mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Sema/IDE] Emit same diagnostics for missing switch cases independent of editor mode
This commit is contained in:
@@ -9,7 +9,9 @@ public enum NonExhaustive {
|
||||
@inlinable
|
||||
public func testNonExhaustive(_ value: NonExhaustive) {
|
||||
switch value { // expected-error {{switch must be exhaustive}}
|
||||
// expected-note@-1 {{add missing cases}}
|
||||
// expected-note@-1 {{add missing case: '.b'}}
|
||||
// expected-note@-2 {{handle unknown values using "@unknown default"}}
|
||||
// expected-note@-3 {{add missing cases}}
|
||||
case .a: break
|
||||
}
|
||||
|
||||
@@ -20,9 +22,12 @@ public func testNonExhaustive(_ value: NonExhaustive) {
|
||||
case .b: break
|
||||
}
|
||||
|
||||
// expected-error@+2 {{switch must be exhaustive}}
|
||||
// expected-note@+1 {{add missing cases}} {{+1:3-3=case .a:\n<#code#>\ncase .b:\n<#code#>\n@unknown default:\n<#code#>\n}}
|
||||
switch value {
|
||||
// expected-error@-1 {{switch must be exhaustive}}
|
||||
// expected-note@-2 {{add missing case: '.a'}} {{+6:3-3=case .a:\n<#code#>\n}}
|
||||
// expected-note@-3 {{add missing case: '.b'}} {{+6:3-3=case .b:\n<#code#>\n}}
|
||||
// expected-note@-4 {{handle unknown values using "@unknown default"}} {{+6:3-3=@unknown default:\n<#fatalError()#>\n}}
|
||||
// expected-note@-5 {{add missing cases}} {{+6:3-3=case .a:\n<#code#>\ncase .b:\n<#code#>\n@unknown default:\n<#fatalError()#>\n}}
|
||||
}
|
||||
|
||||
switch value {
|
||||
|
||||
@@ -31,6 +31,7 @@ func bar(_ e: E2) {
|
||||
// expected-error@-1 {{switch must be exhaustive}}
|
||||
// expected-note@-2 {{add missing case: '.bar(_)'}}
|
||||
// expected-note@-3 {{add missing case: '.baz'}}
|
||||
// expected-note@-4 {{add missing cases}}
|
||||
|
||||
case .foo((_, _, _)): break
|
||||
}
|
||||
|
||||
@@ -498,6 +498,7 @@ func r25178926(_ a : Type) {
|
||||
switch a { // expected-error {{switch must be exhaustive}}
|
||||
// expected-note@-1 {{missing case: '.Foo'}}
|
||||
// expected-note@-2 {{missing case: '.Bar'}}
|
||||
// expected-note@-3 {{add missing cases}}
|
||||
case .Foo where 1 != 100, .Bar where 1 != 100:
|
||||
break
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ enum E {
|
||||
|
||||
func foo1(e : E, i : Int) {
|
||||
switch e {} // expected-error{{switch must be exhaustive}}
|
||||
// expected-note@-1 {{missing case: '.e1'}}
|
||||
// expected-note@-2 {{missing case: '.e2'}}
|
||||
// expected-note@-1 {{add missing cases}}{{13-13=case .e1:\n<#code#>\ncase .e2:\n<#code#>\n}}
|
||||
// expected-note@-2 {{missing case: '.e1'}}
|
||||
// expected-note@-3 {{missing case: '.e2'}}
|
||||
switch i {} // expected-error{{'switch' statement body must have at least one 'case' or 'default' block; add a default case}}{{13-13=default:\n<#code#>\n}}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ func foo1(e : E) {
|
||||
}
|
||||
|
||||
func foo2(i : Int) {
|
||||
// expected-note@+1{{add a default clause}}{{+2:3-3=default:\n<#code#>\n}}
|
||||
switch i { // expected-error{{switch must be exhaustive}}
|
||||
// expected-note@-1{{add a default clause}}{{+3:3-3=default:\n<#code#>\n}}
|
||||
case 1: return
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,7 @@ func testSwitchEnumBoolTuple(_ b1: Bool, b2: Bool, xi: Int) -> Int {
|
||||
switch Cond { // expected-error{{switch must be exhaustive}}
|
||||
// expected-note@-1 {{add missing case: '(false, _)'}}
|
||||
// expected-note@-2 {{add missing case: '(_, false)'}}
|
||||
// expected-note@-3 {{add missing cases}}
|
||||
case (true, true):
|
||||
x += 1
|
||||
}
|
||||
@@ -107,6 +108,7 @@ func testSwitchEnumBoolTuple(_ b1: Bool, b2: Bool, xi: Int) -> Int {
|
||||
switch Cond { // expected-error{{switch must be exhaustive}}
|
||||
// expected-note@-1 {{add missing case: '(true, _)'}}
|
||||
// expected-note@-2 {{add missing case: '(_, false)'}}
|
||||
// expected-note@-3 {{add missing cases}}
|
||||
case (false, true):
|
||||
x += 1
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -diagnostics-editor-mode
|
||||
|
||||
enum E {
|
||||
case e1
|
||||
case e2
|
||||
}
|
||||
|
||||
func foo1(e : E, i : Int) {
|
||||
switch e {} // expected-error{{switch must be exhaustive}}
|
||||
// expected-note@-1{{add missing cases}}{{13-13=case .e1:\n<#code#>\ncase .e2:\n<#code#>\n}}
|
||||
switch i {} // expected-error{{'switch' statement body must have at least one 'case' or 'default' block; add a default case}}{{13-13=default:\n<#code#>\n}}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
// RUN: %target-typecheck-verify-swift -emit-sil -diagnostics-editor-mode
|
||||
|
||||
enum E {
|
||||
case e1
|
||||
case e2
|
||||
}
|
||||
|
||||
func foo1(e : E) {
|
||||
// expected-note@+1{{add missing cases}}{{+2:3-3=case .e2:\n<#code#>\n}}
|
||||
switch e { // expected-error{{switch must be exhaustive}}
|
||||
case .e1: return
|
||||
}
|
||||
}
|
||||
|
||||
func foo2(i : Int) {
|
||||
// expected-note@+1{{add a default clause}}{{+2:3-3=default:\n<#code#>\n}}
|
||||
switch i { // expected-error{{switch must be exhaustive}}
|
||||
case 1: return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user