Skip to content

Commit 968ef77

Browse files
Merge pull request swiftlang#38391 from wongzigii/SR-14883
[SR-14883] Improve diagnostic error message for empty cases
2 parents b6107b4 + efb0639 commit 968ef77

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ ERROR(default_with_where,none,
11391139
"'default' cannot be used with a 'where' guard expression",
11401140
())
11411141
ERROR(case_stmt_without_body,none,
1142-
"%select{'case'|'default'}0 label in a 'switch' should have at least one "
1142+
"%select{'case'|'default'}0 label in a 'switch' must have at least one "
11431143
"executable statement", (bool))
11441144

11451145
// 'try' on statements

test/Constraints/result_builder_diags.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ struct MyView {
652652

653653
@TupleBuilder var invalidSwitchMultiple: some P {
654654
switch Optional.some(1) {
655-
case .none: // expected-error {{'case' label in a 'switch' should have at least one executable statement}}
655+
case .none: // expected-error {{'case' label in a 'switch' must have at least one executable statement}}
656656
case . // expected-error {{expected ':' after 'case'}}
657657
} // expected-error {{expected identifier after '.' expression}}
658658
}

test/Parse/switch.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,27 @@ default:
7272

7373
// Multiple cases per case block
7474
switch x { // expected-error {{switch must be exhaustive}} expected-note{{do you want to add a default clause?}}
75-
case 0: // expected-error {{'case' label in a 'switch' should have at least one executable statement}} {{8-8= break}}
75+
case 0: // expected-error {{'case' label in a 'switch' must have at least one executable statement}} {{8-8= break}}
7676
case 1:
7777
x = 0
7878
}
7979

8080
switch x {
81-
case 0: // expected-error{{'case' label in a 'switch' should have at least one executable statement}} {{8-8= break}}
81+
case 0: // expected-error{{'case' label in a 'switch' must have at least one executable statement}} {{8-8= break}}
8282
default:
8383
x = 0
8484
}
8585

8686
switch x { // expected-error {{switch must be exhaustive}} expected-note{{do you want to add a default clause?}}
8787
case 0:
8888
x = 0
89-
case 1: // expected-error {{'case' label in a 'switch' should have at least one executable statement}} {{8-8= break}}
89+
case 1: // expected-error {{'case' label in a 'switch' must have at least one executable statement}} {{8-8= break}}
9090
}
9191

9292
switch x {
9393
case 0:
9494
x = 0
95-
default: // expected-error {{'default' label in a 'switch' should have at least one executable statement}} {{9-9= break}}
95+
default: // expected-error {{'default' label in a 'switch' must have at least one executable statement}} {{9-9= break}}
9696
}
9797

9898
switch x { // expected-error {{switch must be exhaustive}} expected-note{{do you want to add a default clause?}}
@@ -131,13 +131,13 @@ switch x { // expected-error{{'switch' statement body must have at least one 'ca
131131
}
132132

133133
switch x {
134-
default: // expected-error{{'default' label in a 'switch' should have at least one executable statement}} {{9-9= break}}
134+
default: // expected-error{{'default' label in a 'switch' must have at least one executable statement}} {{9-9= break}}
135135
case 0: // expected-error{{additional 'case' blocks cannot appear after the 'default' block of a 'switch'}}
136136
x = 0
137137
}
138138

139139
switch x {
140-
default: // expected-error{{'default' label in a 'switch' should have at least one executable statement}} {{9-9= break}}
140+
default: // expected-error{{'default' label in a 'switch' must have at least one executable statement}} {{9-9= break}}
141141
default: // expected-error{{additional 'case' blocks cannot appear after the 'default' block of a 'switch'}}
142142
x = 0
143143
}
@@ -148,19 +148,19 @@ default where x == 0: // expected-error{{'default' cannot be used with a 'where'
148148
}
149149

150150
switch x { // expected-error {{switch must be exhaustive}} expected-note{{do you want to add a default clause?}}
151-
case 0: // expected-error {{'case' label in a 'switch' should have at least one executable statement}} {{8-8= break}}
151+
case 0: // expected-error {{'case' label in a 'switch' must have at least one executable statement}} {{8-8= break}}
152152
}
153153

154154
switch x { // expected-error {{switch must be exhaustive}} expected-note{{do you want to add a default clause?}}
155-
case 0: // expected-error{{'case' label in a 'switch' should have at least one executable statement}} {{8-8= break}}
155+
case 0: // expected-error{{'case' label in a 'switch' must have at least one executable statement}} {{8-8= break}}
156156
case 1:
157157
x = 0
158158
}
159159

160160
switch x { // expected-error {{switch must be exhaustive}} expected-note{{do you want to add a default clause?}}
161161
case 0:
162162
x = 0
163-
case 1: // expected-error{{'case' label in a 'switch' should have at least one executable statement}} {{8-8= break}}
163+
case 1: // expected-error{{'case' label in a 'switch' must have at least one executable statement}} {{8-8= break}}
164164
}
165165

166166

@@ -206,15 +206,15 @@ case (_, 2), (var a, _): // expected-error {{'a' must be bound in every pattern}
206206
case (var a, 2), (1, var b): // expected-error {{'a' must be bound in every pattern}} expected-error {{'b' must be bound in every pattern}} expected-warning {{variable 'a' was never used; consider replacing with '_' or removing it}}
207207
()
208208

209-
case (var a, 2): // expected-error {{'case' label in a 'switch' should have at least one executable statement}} {{17-17= break}} expected-warning {{variable 'a' was never used; consider replacing with '_' or removing it}}
209+
case (var a, 2): // expected-error {{'case' label in a 'switch' must have at least one executable statement}} {{17-17= break}} expected-warning {{variable 'a' was never used; consider replacing with '_' or removing it}}
210210
case (1, _):
211211
()
212212

213-
case (_, 2): // expected-error {{'case' label in a 'switch' should have at least one executable statement}} {{13-13= break}}
213+
case (_, 2): // expected-error {{'case' label in a 'switch' must have at least one executable statement}} {{13-13= break}}
214214
case (1, var a): // expected-warning {{variable 'a' was never used; consider replacing with '_' or removing it}}
215215
()
216216

217-
case (var a, 2): // expected-error {{'case' label in a 'switch' should have at least one executable statement}} {{17-17= break}} expected-warning {{variable 'a' was never used; consider replacing with '_' or removing it}}
217+
case (var a, 2): // expected-error {{'case' label in a 'switch' must have at least one executable statement}} {{17-17= break}} expected-warning {{variable 'a' was never used; consider replacing with '_' or removing it}}
218218
case (1, var b): // expected-warning {{variable 'b' was never used; consider replacing with '_' or removing it}}
219219
()
220220

@@ -238,7 +238,7 @@ case (var a, var b), (var b, var a): // expected-warning {{variable 'a' was neve
238238
// expected-warning@-2 {{case is already handled by previous patterns; consider removing it}}
239239
()
240240

241-
case (_, 2): // expected-error {{'case' label in a 'switch' should have at least one executable statement}} {{13-13= break}}
241+
case (_, 2): // expected-error {{'case' label in a 'switch' must have at least one executable statement}} {{13-13= break}}
242242
case (1, _):
243243
()
244244
}
@@ -353,27 +353,27 @@ func f1(x: String, y: Whichever) {
353353

354354

355355
switch Whatever.Thing {
356-
case .Thing: // expected-error{{'case' label in a 'switch' should have at least one executable statement}} {{13-13= break}}
356+
case .Thing: // expected-error{{'case' label in a 'switch' must have at least one executable statement}} {{13-13= break}}
357357
@unknown case _:
358358
x = 0
359359
}
360360

361361
switch Whatever.Thing {
362-
case .Thing: // expected-error{{'case' label in a 'switch' should have at least one executable statement}} {{13-13= break}}
362+
case .Thing: // expected-error{{'case' label in a 'switch' must have at least one executable statement}} {{13-13= break}}
363363
@unknown default:
364364
x = 0
365365
}
366366

367367
switch Whatever.Thing {
368368
case .Thing:
369369
x = 0
370-
@unknown case _: // expected-error {{'case' label in a 'switch' should have at least one executable statement}} {{17-17= break}}
370+
@unknown case _: // expected-error {{'case' label in a 'switch' must have at least one executable statement}} {{17-17= break}}
371371
}
372372

373373
switch Whatever.Thing {
374374
case .Thing:
375375
x = 0
376-
@unknown default: // expected-error {{'default' label in a 'switch' should have at least one executable statement}} {{18-18= break}}
376+
@unknown default: // expected-error {{'default' label in a 'switch' must have at least one executable statement}} {{18-18= break}}
377377
}
378378

379379

test/stmt/statements.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func matching_pattern_recursion() {
412412
// <rdar://problem/18776073> Swift's break operator in switch should be indicated in errors
413413
func r18776073(_ a : Int?) {
414414
switch a {
415-
case nil: // expected-error {{'case' label in a 'switch' should have at least one executable statement}} {{14-14= break}}
415+
case nil: // expected-error {{'case' label in a 'switch' must have at least one executable statement}} {{14-14= break}}
416416
case _?: break
417417
}
418418
}

0 commit comments

Comments
 (0)