From 894c932ad018333a93ad97ff3facad045645a5f0 Mon Sep 17 00:00:00 2001 From: Pavel Yaskevich Date: Mon, 14 Mar 2022 10:07:13 -0700 Subject: [PATCH] [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. --- lib/Sema/CSApply.cpp | 3 ++- test/expr/closure/multi_statement.swift | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/Sema/CSApply.cpp b/lib/Sema/CSApply.cpp index 687c216796fd2..0daf5a6756ea3 100644 --- a/lib/Sema/CSApply.cpp +++ b/lib/Sema/CSApply.cpp @@ -2281,7 +2281,8 @@ namespace { ExprRewriter(ConstraintSystem &cs, Solution &solution, Optional target, bool suppressDiagnostics) - : cs(cs), dc(cs.DC), solution(solution), target(target), + : cs(cs), dc(target ? target->getDeclContext() : cs.DC), + solution(solution), target(target), SuppressDiagnostics(suppressDiagnostics) {} ConstraintSystem &getConstraintSystem() const { return cs; } diff --git a/test/expr/closure/multi_statement.swift b/test/expr/closure/multi_statement.swift index f00ccf1c284e4..efb2b1105d96c 100644 --- a/test/expr/closure/multi_statement.swift +++ b/test/expr/closure/multi_statement.swift @@ -233,3 +233,19 @@ func test_local_function_capturing_vars() { } } } + +func test_taps_type_checked_with_correct_decl_context() { + struct Path { + func contains(_: T) -> Bool where T: StringProtocol { return false } + } + + let paths: [Path] = [] + let strs: [String] = [] + + _ = paths.filter { path in + for str in strs where path.contains("\(str).hello") { + return true + } + return false + } +}