Skip to content

Commit d86725c

Browse files
authored
[ConstraintSystem] Ignore patterns in linked expression analysis (#18487)
Fixes an assertion hit in "pattern in binary expression" case. rdar://problem/41071587
1 parent 913f371 commit d86725c

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

lib/Sema/CSGen.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ namespace {
177177

178178
/// \brief Ignore declarations.
179179
bool walkToDeclPre(Decl *decl) override { return false; }
180+
181+
/// \brief Ignore patterns.
182+
std::pair<bool, Pattern*> walkToPatternPre(Pattern *pat) override {
183+
return { false, pat };
184+
}
185+
186+
/// \brief Ignore types.
187+
bool walkToTypeLocPre(TypeLoc &TL) override { return false; }
180188
};
181189

182190
/// Given a collection of "linked" expressions, analyzes them for
@@ -338,6 +346,14 @@ namespace {
338346

339347
/// \brief Ignore declarations.
340348
bool walkToDeclPre(Decl *decl) override { return false; }
349+
350+
/// \brief Ignore patterns.
351+
std::pair<bool, Pattern*> walkToPatternPre(Pattern *pat) override {
352+
return { false, pat };
353+
}
354+
355+
/// \brief Ignore types.
356+
bool walkToTypeLocPre(TypeLoc &TL) override { return false; }
341357
};
342358

343359
/// For a given expression, given information that is global to the

test/IDE/complete_crashes.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,13 @@ extension Foo {
357357
// RDAR_41234606-DAG: Decl[AssociatedType]/Super: .Element; name=Element
358358
// RDAR_41234606-DAG: Decl[AssociatedType]/Super: .Iterator; name=Iterator
359359
// RDAR_41234606: End completions
360+
361+
// rdar://problem/41071587
362+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=RDAR_41071587 -source-filename=%s | %FileCheck %s -check-prefix=RDAR_41071587
363+
func test_41071587(x: Any) {
364+
switch x {
365+
case (let (_, _)) #^RDAR_41071587^#:
366+
()
367+
}
368+
}
369+
// RDAR_41071587: Begin completions

test/Parse/matching_patterns.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ case (_, var e, 3) +++ (1, 2, 3):
286286
// expected-error@-1{{'_' can only appear in a pattern}}
287287
// expected-error@-2{{'var' binding pattern cannot appear in an expression}}
288288
()
289+
case (let (_, _, _)) + 1:
290+
// expected-error@-1 2 {{'var' binding pattern cannot appear in an expression}}
291+
// expected-error@-2 {{expression pattern of type 'Int' cannot match values of type '(Int, Int, Int)'}}
292+
()
289293
}
290294

291295
// FIXME: We don't currently allow subpatterns for "isa" patterns that

0 commit comments

Comments
 (0)