diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index 3da3868e6568b..d9f1d46a238df 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -11020,6 +11020,11 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar, if (contextualTy->isTypeVariableOrMember()) return false; + // Cannot propagate pack expansion type from context, + // it has to be handled by type matching logic. + if (contextualTy->is()) + return false; + // If contextual type has an error, let's wait for inference, // otherwise contextual would interfere with diagnostics. if (contextualTy->hasError()) diff --git a/test/Constraints/pack-expansion-expressions.swift b/test/Constraints/pack-expansion-expressions.swift index f185a2061910f..af71c93c095db 100644 --- a/test/Constraints/pack-expansion-expressions.swift +++ b/test/Constraints/pack-expansion-expressions.swift @@ -261,3 +261,13 @@ func invalidRepeat(t: repeat each T) { _ = [repeat each t] // expected-error@-1 {{value pack expansion can only appear inside a function argument list or tuple element}} } + +func test_pack_expansions_with_closures() { + func takesVariadicFunction(function: (repeat each T) -> Int) {} + + func test(fn: (Int, String) -> Int, x: Int) { + takesVariadicFunction { fn(x, "") } // Ok + takesVariadicFunction { y in fn(x, y) } // Ok + takesVariadicFunction { y, z in fn(y, z) } // Ok + } +}