Skip to content

Commit 894c932

Browse files
committed
[CSApply] Use decl context of target when applying solution to it
Solution application target can have its declaration context differ from one used for constraint system, since target could be e.g. a pattern associated with pattern binding declaration, a statement or a sub-element of one (e.g. where clause) used in a closure etc.
1 parent b6047e2 commit 894c932

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,8 @@ namespace {
22812281
ExprRewriter(ConstraintSystem &cs, Solution &solution,
22822282
Optional<SolutionApplicationTarget> target,
22832283
bool suppressDiagnostics)
2284-
: cs(cs), dc(cs.DC), solution(solution), target(target),
2284+
: cs(cs), dc(target ? target->getDeclContext() : cs.DC),
2285+
solution(solution), target(target),
22852286
SuppressDiagnostics(suppressDiagnostics) {}
22862287

22872288
ConstraintSystem &getConstraintSystem() const { return cs; }

test/expr/closure/multi_statement.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,19 @@ func test_local_function_capturing_vars() {
233233
}
234234
}
235235
}
236+
237+
func test_taps_type_checked_with_correct_decl_context() {
238+
struct Path {
239+
func contains<T>(_: T) -> Bool where T: StringProtocol { return false }
240+
}
241+
242+
let paths: [Path] = []
243+
let strs: [String] = []
244+
245+
_ = paths.filter { path in
246+
for str in strs where path.contains("\(str).hello") {
247+
return true
248+
}
249+
return false
250+
}
251+
}

0 commit comments

Comments
 (0)