Skip to content

Commit 187647d

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.
1 parent b92a4eb commit 187647d

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
@@ -7577,7 +7577,8 @@ bool ConstraintSystem::applySolutionFixes(Expr *E, const Solution &solution) {
75777577
auto *transformedExpr = result->second.second;
75787578
// Since this closure has been transformed into something
75797579
// else let's look inside transformed expression instead.
7580-
return {true, transformedExpr};
7580+
transformedExpr->walk(*this);
7581+
return {false, E};
75817582
}
75827583
}
75837584

test/Constraints/function_builder_diags.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,18 @@ struct SR11440 {
199199
})
200200
}
201201
}
202+
203+
func acceptInt(_: Int, _: () -> Void) { }
204+
205+
// SR-11350 crash due to improper recontextualization.
206+
func erroneousSR11350(x: Int) {
207+
tuplify(true) { b in
208+
17
209+
x + 25
210+
Optional(tuplify(false) { b in
211+
if b {
212+
acceptInt(0) { }
213+
}
214+
}).domap(0) // expected-error{{value of type 'Optional<()>' has no member 'domap'}}
215+
}
216+
}

0 commit comments

Comments
 (0)