Skip to content

Commit d7ec5fe

Browse files
committed
[CSSimplify] Don't propagate contextual parameter type if it's a pack expansion
Pack expansion types are handled by matching logic, optimization that attempts to propagate types into the body of the closure should consider them unsuitable even if the pack expansion matches a single parameter.
1 parent 294342a commit d7ec5fe

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10987,6 +10987,11 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
1098710987
if (contextualTy->isTypeVariableOrMember())
1098810988
return false;
1098910989

10990+
// Cannot propagate pack expansion type from context,
10991+
// it has to be handled by type matching logic.
10992+
if (contextualTy->is<PackExpansionType>())
10993+
return false;
10994+
1099010995
// If contextual type has an error, let's wait for inference,
1099110996
// otherwise contextual would interfere with diagnostics.
1099210997
if (contextualTy->hasError())

test/Constraints/pack-expansion-expressions.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,13 @@ func packOutsideExpansion<each T>(_ t: repeat each T) {
240240
_ = each tuple.element
241241
// expected-error@-1{{pack reference 'T' can only appear in pack expansion}}
242242
}
243+
244+
func test_pack_expansions_with_closures() {
245+
func takesVariadicFunction<each T>(function: (repeat each T) -> Int) {}
246+
247+
func test(fn: (Int, String) -> Int, x: Int) {
248+
takesVariadicFunction { fn(x, "") } // Ok
249+
takesVariadicFunction { y in fn(x, y) } // Ok
250+
takesVariadicFunction { y, z in fn(y, z) } // Ok
251+
}
252+
}

0 commit comments

Comments
 (0)