Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7344,17 +7344,20 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
// match `$T3` and propagate `Pack{Int}` to `$T2`.
//
// This is also important for situations like: `$T2 conv (Int, $T_exp)`
// becuase expansion could be defaulted to an empty pack which means
// because expansion could be defaulted to an empty pack which means
// that under substitution that element would disappear and the type
// would be just `(Int)`.
//
// Notable exception here is `Any` which doesn't require wrapping and
// would be handled by existental promotion in cases where it's allowed.
// Notable exceptions here are: `Any` which doesn't require wrapping and
// would be handled by an existential promotion in cases where it's allowed,
// and `Optional<T>` which would be handled by optional injection.
if (isTupleWithUnresolvedPackExpansion(origType1) ||
isTupleWithUnresolvedPackExpansion(origType2)) {
if (isa<TupleType>(desugar1) != isa<TupleType>(desugar2) &&
!isa<InOutType>(desugar1) &&
!isa<InOutType>(desugar2) &&
!desugar1->getOptionalObjectType() &&
!desugar2->getOptionalObjectType() &&
!desugar1->isAny() &&
!desugar2->isAny()) {
return matchTypes(
Expand Down
14 changes: 14 additions & 0 deletions test/Constraints/variadic_generic_constraints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,17 @@ func badCallToZip<each T, each U>(t: repeat each T, u: repeat each U) {
// expected-error@-1 {{global function 'zip(t:u:)' requires the type packs 'each T' and 'each U' have the same shape}}
// expected-error@-2 {{pack expansion requires that 'each U' and 'each T' have the same shape}}
}

do {
func test<A, B, each C>(
_: A,
_: B,
_: repeat each C
) throws -> (A, B, repeat each C) {
fatalError()
}

func test() {
guard let _ = try? test(1, 2, 3) else { return } // Ok
}
}