diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index d416cd065fd3f..8ce2afd77c9f4 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -11404,6 +11404,7 @@ ConstraintSystem::simplifyApplicableFnConstraint( FunctionType::get(trailingClosureTypes, callAsFunctionResultTy, FunctionType::ExtInfo()); + increaseScore(SK_DisfavoredOverload); // Form an unsolved constraint to apply trailing closures to a // callable type produced by `.init`. This constraint would become // active when `callableType` is bound. diff --git a/test/Constraints/result_builder_callAsFunction.swift b/test/Constraints/result_builder_callAsFunction.swift new file mode 100644 index 0000000000000..a1546345b94d9 --- /dev/null +++ b/test/Constraints/result_builder_callAsFunction.swift @@ -0,0 +1,36 @@ +// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5 -debug-constraints > %t.log 2>&1 +// RUN: %FileCheck %s < %t.log + +// REQUIRES: objc_interop +// REQUIRES: OS=macosx + +protocol View {} +protocol Callable {} + +struct EmptyView : View {} + +@resultBuilder struct ViewBuilder { + static func buildBlock(_ content: Content) -> Content where Content : View { fatalError() } +} + +extension Callable { + func callAsFunction(@ViewBuilder _: () -> T) -> some View { EmptyView() } +} + +struct MyView : View { + init(v: Int, @ViewBuilder _: () -> Content) {} +} + +extension MyView : Callable where Content == EmptyView { + init(v: Int) {} +} + +// CHECK: (overload set choice binding $T6 := (Int) -> MyView<{{.*}}>) +// CHECK-NEXT: (increasing score due to disfavored overload) +// CHECK-NEXT: (solution is worse than the best solution) + +func test() -> some View { + return MyView(v: 42) { + return EmptyView() + } +}