Skip to content

Commit 913733f

Browse files
committed
[CS] Dont wrap packexp in extra layer of expansion
Arguments that were already pack expansions were being wrapped in a second layer--preventing some would-be unambiguous overloads from resolving. This adds a check to avoid doing that.
1 parent e5d0cd4 commit 913733f

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/Sema/CSRanking.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,11 +703,16 @@ bool CompareDeclSpecializationRequest::evaluate(
703703
paramIdx != numParams; ++paramIdx) {
704704
const auto &param = params2[paramIdx];
705705
auto paramTy = param.getOldType();
706+
auto argIndices = matching->parameterBindings[paramIdx];
707+
if (argIndices.empty())
708+
continue;
706709

707710
if (paramListInfo.isVariadicGenericParameter(paramIdx) &&
708-
isPackExpansionType(paramTy)) {
711+
isPackExpansionType(paramTy) &&
712+
(argIndices.size() > 1 ||
713+
!isPackExpansionType(args[argIndices.front()].getOldType()))) {
709714
SmallVector<Type, 2> argTypes;
710-
for (auto argIdx : matching->parameterBindings[paramIdx]) {
715+
for (auto argIdx : argIndices) {
711716
// Don't prefer `T...` over `repeat each T`.
712717
if (args[argIdx].isVariadic())
713718
return completeResult(false);
@@ -721,7 +726,7 @@ bool CompareDeclSpecializationRequest::evaluate(
721726
continue;
722727
}
723728

724-
for (auto argIdx : matching->parameterBindings[paramIdx]) {
729+
for (auto argIdx : argIndices) {
725730
const auto &arg = args[argIdx];
726731
// Always prefer non-variadic version when possible.
727732
if (arg.isVariadic())

test/Constraints/variadic_generic_overload_ranking.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,13 @@ func test_ranking_with_multiple_expansions() {
8585
// CHECK-NEXT: {{.*}} = function_ref @$s33variadic_generic_overload_ranking05test_D25_with_multiple_expansionsyyF7BuilderL_V5buildyAaByyF5TupleL_VyxxQp_tGxxQpRvzAA1PRzlFZ : $@convention(method) <each τ_0_0 where repeat each τ_0_0 : P> (@pack_guaranteed Pack{repeat each τ_0_0}, @thin Builder.Type) -> Tuple<(repeat each τ_0_0)>
8686
_ = Builder.build(Empty(), Tuple<(Int, String)>((42, "")))
8787
}
88+
protocol Q: P {}
89+
90+
func test_ranking_with_protocol_refinement() {
91+
func f<each T: Q>(_ a: repeat each T) {}
92+
func f<each T: P>(_ a: repeat each T) {}
93+
struct S: Q {}
94+
// CHECK: // function_ref f #1 <each A>(_:) in test_ranking_with_protocol_refinement()
95+
// CHECK-NEXT: {{.*}} = function_ref @$s33variadic_generic_overload_ranking05test_D25_with_protocol_refinementyyF1fL_yyxxQpRvzAA1QRzlF : $@convention(thin) <each τ_0_0 where repeat each τ_0_0 : Q> (@pack_guaranteed Pack{repeat each τ_0_0}) -> ()
96+
f(S())
97+
}

0 commit comments

Comments
 (0)