Skip to content

Commit 14076df

Browse files
committed
Fix test failures
1 parent ac7529f commit 14076df

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/Parse/ParseStmt.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,10 +1635,12 @@ Parser::parseStmtConditionElement(SmallVectorImpl<StmtConditionElement> &result,
16351635

16361636
declRefExpr->setImplicit();
16371637
Init = makeParserResult(declRefExpr);
1638-
} else if (!ThePattern.isNull()) {
1638+
} else if (!ThePattern.isNull() && BindingKindStr != "case") {
16391639
// If the pattern is present but isn't an identifier, the user wrote
16401640
// something invalid like `let foo.bar`. Emit a special diagnostic for this,
16411641
// with a fix-it prepending "<#identifier#> = "
1642+
// - We don't emit this fix-it if the user wrote `case let` (etc),
1643+
// since the shorthand syntax isn't available for pattern matching
16421644
auto diagLoc = ThePattern.get()->getSemanticsProvidingPattern()->getStartLoc();
16431645
diagnose(diagLoc, diag::conditional_var_valid_identifiers_only)
16441646
.fixItInsert(diagLoc, "<#identifier#> = ");

test/stmt/if_while_var.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class B {} // expected-note * {{did you mean 'B'?}}
5555
class D : B {}// expected-note * {{did you mean 'D'?}}
5656

5757
// TODO poor recovery in these cases
58-
if let {} // expected-error {{expected '{' after 'if' condition}} expected-error {{pattern matching in a condition requires the 'case' keyword}}
59-
if let x = { } // expected-error{{'{' after 'if'}} expected-error {{variable binding in a condition requires an initializer}} expected-error{{initializer for conditional binding must have Optional type, not '() -> ()'}}
58+
if let {} // expected-error {{expected '{' after 'if' condition}} expected-error {{pattern matching in a condition requires the 'case' keyword}} expected-error {{unwrap condition requires a valid identifier}}
59+
if let x = { } // expected-error{{'{' after 'if'}} expected-error{{initializer for conditional binding must have Optional type, not '() -> ()'}}
6060
// expected-warning@-1{{value 'x' was defined but never used}}
6161

6262
if let x = foo() {

0 commit comments

Comments
 (0)