Skip to content

Commit 10ed175

Browse files
committed
[CS] Set the naming pattern in markInvalid
This normally gets populated by successful type-checking, we still want to populate it if we fail though to avoid attempting to type-check the parent statement again.
1 parent 84847bc commit 10ed175

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

lib/Sema/SyntacticElementTarget.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@ void SyntacticElementTarget::markInvalid() const {
307307

308308
PreWalkResult<Pattern *> walkToPatternPre(Pattern *P) override {
309309
P->setType(ErrorType::get(Ctx));
310+
311+
// For a named pattern, set it on the variable. This stops us from
312+
// attempting to double-type-check variables we've already type-checked.
313+
if (auto *NP = dyn_cast<NamedPattern>(P))
314+
NP->getDecl()->setNamingPattern(NP);
315+
310316
return Action::Continue(P);
311317
}
312318

test/Constraints/issue-66553.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
func baz(y: [Int], z: Int) -> Int {
66
switch z {
7-
case y[let z]: // expected-error 2{{'let' binding pattern cannot appear in an expression}}
7+
case y[let z]: // expected-error {{'let' binding pattern cannot appear in an expression}}
88
z
99
default:
1010
z

test/Parse/matching_patterns.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func testNonBinding5(_ x: Int, y: [Int]) {
406406
func testNonBinding6(y: [Int], z: Int) -> Int {
407407
switch 0 {
408408
// We treat 'z' here as a binding, which is invalid.
409-
case let y[z]: // expected-error 2{{pattern variable binding cannot appear in an expression}}
409+
case let y[z]: // expected-error {{pattern variable binding cannot appear in an expression}}
410410
z
411411
case y[z]: // This is fine
412412
0

0 commit comments

Comments
 (0)