Skip to content

Commit 91ae0e0

Browse files
authored
Merge pull request #82326 from xedin/rdar-152940244
[CSSimplify] VariadicGenerics: Don't attempt to wrap optional into on…
2 parents a2ded36 + 6cfbafd commit 91ae0e0

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7344,17 +7344,20 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
73447344
// match `$T3` and propagate `Pack{Int}` to `$T2`.
73457345
//
73467346
// This is also important for situations like: `$T2 conv (Int, $T_exp)`
7347-
// becuase expansion could be defaulted to an empty pack which means
7347+
// because expansion could be defaulted to an empty pack which means
73487348
// that under substitution that element would disappear and the type
73497349
// would be just `(Int)`.
73507350
//
7351-
// Notable exception here is `Any` which doesn't require wrapping and
7352-
// would be handled by existental promotion in cases where it's allowed.
7351+
// Notable exceptions here are: `Any` which doesn't require wrapping and
7352+
// would be handled by an existential promotion in cases where it's allowed,
7353+
// and `Optional<T>` which would be handled by optional injection.
73537354
if (isTupleWithUnresolvedPackExpansion(origType1) ||
73547355
isTupleWithUnresolvedPackExpansion(origType2)) {
73557356
if (isa<TupleType>(desugar1) != isa<TupleType>(desugar2) &&
73567357
!isa<InOutType>(desugar1) &&
73577358
!isa<InOutType>(desugar2) &&
7359+
!desugar1->getOptionalObjectType() &&
7360+
!desugar2->getOptionalObjectType() &&
73587361
!desugar1->isAny() &&
73597362
!desugar2->isAny()) {
73607363
return matchTypes(

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)