Skip to content

Commit ca39957

Browse files
authored
Merge pull request #82374 from xedin/rdar-152940244-6.2
[6.2][CSSimplify] VariadicGenerics: Don't attempt to wrap optional into on…
2 parents f589a7f + cb9925d commit ca39957

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7345,16 +7345,20 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
73457345
// match `$T3` and propagate `Pack{Int}` to `$T2`.
73467346
//
73477347
// This is also important for situations like: `$T2 conv (Int, $T_exp)`
7348-
// becuase expansion could be defaulted to an empty pack which means
7348+
// because expansion could be defaulted to an empty pack which means
73497349
// that under substitution that element would disappear and the type
73507350
// would be just `(Int)`.
73517351
//
7352-
// Notable exception here is `Any` which doesn't require wrapping and
7353-
// would be handled by existental promotion in cases where it's allowed.
7352+
// Notable exceptions here are: `Any` which doesn't require wrapping and
7353+
// would be handled by an existential promotion in cases where it's allowed,
7354+
// and `Optional<T>` which would be handled by optional injection.
73547355
if (isTupleWithUnresolvedPackExpansion(origType1) ||
73557356
isTupleWithUnresolvedPackExpansion(origType2)) {
7356-
if (desugar1->is<TupleType>() != desugar2->is<TupleType>() &&
7357-
(!desugar1->isAny() && !desugar2->isAny())) {
7357+
if (isa<TupleType>(desugar1) != isa<TupleType>(desugar2) &&
7358+
!desugar1->getOptionalObjectType() &&
7359+
!desugar2->getOptionalObjectType() &&
7360+
!desugar1->isAny() &&
7361+
!desugar2->isAny()) {
73587362
return matchTypes(
73597363
desugar1->is<TupleType>() ? type1
73607364
: TupleType::get({type1}, getASTContext()),

test/Constraints/variadic_generic_constraints.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,17 @@ func badCallToZip<each T, each U>(t: repeat each T, u: repeat each U) {
7676
// expected-error@-1 {{global function 'zip(t:u:)' requires the type packs 'each T' and 'each U' have the same shape}}
7777
// expected-error@-2 {{pack expansion requires that 'each U' and 'each T' have the same shape}}
7878
}
79+
80+
do {
81+
func test<A, B, each C>(
82+
_: A,
83+
_: B,
84+
_: repeat each C
85+
) throws -> (A, B, repeat each C) {
86+
fatalError()
87+
}
88+
89+
func test() {
90+
guard let _ = try? test(1, 2, 3) else { return } // Ok
91+
}
92+
}

0 commit comments

Comments
 (0)