Skip to content

Commit 9399451

Browse files
committed
[ConstraintSystem] Fix result builder discovery in leading-dot syntax calls
Leading-dot syntax allows implicitly unwrapping result type to form a base type of the call, `getOpenedResultBuilderTypeFor` needs to account for that. Resolves: #60586
1 parent 04f1cde commit 9399451

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9852,7 +9852,9 @@ static Type getOpenedResultBuilderTypeFor(ConstraintSystem &cs,
98529852
auto *calleeLocator = cs.getCalleeLocator(cs.getConstraintLocator(locator));
98539853
auto selectedOverload = cs.findSelectedOverloadFor(calleeLocator);
98549854
if (!(selectedOverload &&
9855-
selectedOverload->choice.getKind() == OverloadChoiceKind::Decl))
9855+
(selectedOverload->choice.getKind() == OverloadChoiceKind::Decl ||
9856+
selectedOverload->choice.getKind() ==
9857+
OverloadChoiceKind::DeclViaUnwrappedOptional)))
98569858
return Type();
98579859

98589860
auto *choice = selectedOverload->choice.getDecl();

test/Constraints/result_builder.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,3 +1200,19 @@ func test_callAsFunction_with_resultBuilder() {
12001200
test_callAsFunction_with_resultBuilder()
12011201
// CHECK: (0, "with parens", true)
12021202
// CHECK: (1, "without parens", true)
1203+
1204+
do {
1205+
struct S {
1206+
static func test<T>(@TupleBuilder _ body: (Bool) -> T) -> S {
1207+
print(body(true))
1208+
return .init()
1209+
}
1210+
}
1211+
1212+
let _: S? = .test {
1213+
42
1214+
""
1215+
[$0]
1216+
}
1217+
// CHECK: (42, "", [true])
1218+
}

0 commit comments

Comments
 (0)