Skip to content

Commit b4937be

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 e78cf22 commit b4937be

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
@@ -11020,6 +11020,11 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
1102011020
if (contextualTy->isTypeVariableOrMember())
1102111021
return false;
1102211022

11023+
// Cannot propagate pack expansion type from context,
11024+
// it has to be handled by type matching logic.
11025+
if (contextualTy->is<PackExpansionType>())
11026+
return false;
11027+
1102311028
// If contextual type has an error, let's wait for inference,
1102411029
// otherwise contextual would interfere with diagnostics.
1102511030
if (contextualTy->hasError())

test/Constraints/pack-expansion-expressions.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,13 @@ func invalidRepeat<each T>(t: repeat each T) {
261261
_ = [repeat each t]
262262
// expected-error@-1 {{value pack expansion can only appear inside a function argument list or tuple element}}
263263
}
264+
265+
func test_pack_expansions_with_closures() {
266+
func takesVariadicFunction<each T>(function: (repeat each T) -> Int) {}
267+
268+
func test(fn: (Int, String) -> Int, x: Int) {
269+
takesVariadicFunction { fn(x, "") } // Ok
270+
takesVariadicFunction { y in fn(x, y) } // Ok
271+
takesVariadicFunction { y, z in fn(y, z) } // Ok
272+
}
273+
}

0 commit comments

Comments
 (0)