Skip to content

Commit 6052e90

Browse files
committed
[CSSimplify] Don't enable OneWayBindParam for result builder transformed closures
This means two things: - transformed closures behave just like regular multi-statement closures - It's now possible to pass partially resolved parameter types into the closure which helps with diagnostics.
1 parent 91f7854 commit 6052e90

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10805,8 +10805,7 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
1080510805
// type as seen in the body of the closure and the external parameter
1080610806
// type.
1080710807
bool oneWayConstraints =
10808-
getASTContext().LangOpts.hasFeature(Feature::OneWayClosureParameters) ||
10809-
resultBuilderType;
10808+
getASTContext().LangOpts.hasFeature(Feature::OneWayClosureParameters);
1081010809

1081110810
auto *paramList = closure->getParameters();
1081210811
SmallVector<AnyFunctionType::Param, 4> parameters;

test/Constraints/result_builder_diags.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ func wrapperifyInfer<T, U>(_ cond: Bool, @WrapperBuilder body: (U) -> T) -> T {
622622
}
623623

624624
let intValue = 17
625-
wrapperifyInfer(true) { x in // expected-error{{unable to infer type of a closure parameter 'x' in the current context}}
625+
_ = wrapperifyInfer(true) { x in // Ok
626626
intValue + x
627627
}
628628

@@ -938,3 +938,17 @@ func test_dependent_member_with_unresolved_base_type() {
938938
}
939939
}
940940
}
941+
942+
func test_partially_resolved_closure_params() {
943+
struct S<T> {
944+
var a: String = ""
945+
}
946+
947+
func test<T>(@TupleBuilder _: (S<T>) -> T) { // expected-note {{in call to function 'test'}}
948+
}
949+
950+
test { // expected-error {{generic parameter 'T' could not be inferred}}
951+
$0.a
952+
42
953+
}
954+
}

0 commit comments

Comments
 (0)