Skip to content

Commit 15538f5

Browse files
committed
[Type checker] Don't replace function builder closures with their bodies.
When diagnosing failures in a function builder closure, we were unnecessarily replacing the closure expression with its body, destroying the AST and resulting in assertions due to DeclContext mismatches. Fixes SR-11350 / rdar://problem/54590425. (cherry picked from commit 187647d)
1 parent e51770b commit 15538f5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7688,7 +7688,8 @@ bool ConstraintSystem::applySolutionFixes(Expr *E, const Solution &solution) {
76887688
auto *transformedExpr = result->second.second;
76897689
// Since this closure has been transformed into something
76907690
// else let's look inside transformed expression instead.
7691-
return {true, transformedExpr};
7691+
transformedExpr->walk(*this);
7692+
return {false, E};
76927693
}
76937694
}
76947695

test/Constraints/function_builder_diags.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,18 @@ func test_51167632() -> some P {
172172
// expected-note@-1 {{explicitly specify the generic arguments to fix this issue}} {{10-10=<<#L: P#>>}}
173173
})
174174
}
175+
176+
func acceptInt(_: Int, _: () -> Void) { }
177+
178+
// SR-11350 crash due to improper recontextualization.
179+
func erroneousSR11350(x: Int) {
180+
tuplify(true) { b in
181+
17
182+
x + 25
183+
Optional(tuplify(false) { b in
184+
if b {
185+
acceptInt(0) { }
186+
}
187+
}).domap(0) // expected-error{{value of type 'Optional<()>' has no member 'domap'}}
188+
}
189+
}

0 commit comments

Comments
 (0)