Skip to content

[CSSimplify] Don't enable OneWayBindParam for result builder transformed closures #64443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10996,8 +10996,7 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
// type as seen in the body of the closure and the external parameter
// type.
bool oneWayConstraints =
getASTContext().LangOpts.hasFeature(Feature::OneWayClosureParameters) ||
resultBuilderType;
getASTContext().LangOpts.hasFeature(Feature::OneWayClosureParameters);

auto *paramList = closure->getParameters();
SmallVector<AnyFunctionType::Param, 4> parameters;
Expand Down
16 changes: 15 additions & 1 deletion test/Constraints/result_builder_diags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ func wrapperifyInfer<T, U>(_ cond: Bool, @WrapperBuilder body: (U) -> T) -> T {
}

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

Expand Down Expand Up @@ -1001,3 +1001,17 @@ func test_requirement_failure_in_buildBlock() {
}
}
}

func test_partially_resolved_closure_params() {
struct S<T> {
var a: String = ""
}

func test<T>(@TupleBuilder _: (S<T>) -> T) { // expected-note {{in call to function 'test'}}
}

test { // expected-error {{generic parameter 'T' could not be inferred}}
$0.a
42
}
}