Skip to content

Commit 5d7a8a1

Browse files
committed
[test] Add a couple of extra if expression tests
1 parent f0e487d commit 5d7a8a1

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

test/expr/unary/if_expr.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,14 +557,26 @@ func stmts() {
557557
return
558558
}
559559

560-
switch if .random() { true } else { false } { // expected-error {{'if' may only be used as expression in return, throw, or as the source of an assignment}}
561-
case _ where if .random() { true } else { false }: // expected-error {{'if' may only be used as expression in return, throw, or as the source of an assignment}}
560+
switch if .random() { true } else { false } {
561+
// expected-error@-1 {{'if' may only be used as expression in return, throw, or as the source of an assignment}}
562+
case _ where if .random() { true } else { false }:
563+
// expected-error@-1 {{'if' may only be used as expression in return, throw, or as the source of an assignment}}
564+
break
565+
case if .random() { true } else { false }:
566+
// expected-error@-1 {{'if' may only be used as expression in return, throw, or as the source of an assignment}}
567+
break
568+
case if .random() { true } else { false } && false:
569+
// expected-error@-1 {{'if' may only be used as expression in return, throw, or as the source of an assignment}}
562570
break
563571
default:
564572
break
565573
}
566574

567-
for b in [true] where if b { true } else { false } {} // expected-error {{'if' may only be used as expression in return, throw, or as the source of an assignment}}
575+
for b in [true] where if b { true } else { false } {}
576+
// expected-error@-1 {{'if' may only be used as expression in return, throw, or as the source of an assignment}}
577+
578+
for _ in if .random() { [true] } else { [false] } {}
579+
// expected-error@-1 {{'if' may only be used as expression in return, throw, or as the source of an assignment}}
568580

569581
// Make sure this doesn't parse as an if expr pattern with a label.
570582
let x = 0

0 commit comments

Comments
 (0)