Skip to content

Commit 10bd676

Browse files
authored
Merge pull request #82471 from xedin/rdar-154221449-6.2
[6.2][CSSimplify] Narrow down tuple wrapping for pack expansion matching
2 parents 8fcffa8 + 767dbc0 commit 10bd676

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7359,9 +7359,15 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
73597359
// and `Optional<T>` which would be handled by optional injection.
73607360
if (isTupleWithUnresolvedPackExpansion(origType1) ||
73617361
isTupleWithUnresolvedPackExpansion(origType2)) {
7362+
auto isTypeVariableWrappedInOptional = [](Type type) {
7363+
if (type->getOptionalObjectType()) {
7364+
return type->lookThroughAllOptionalTypes()->isTypeVariableOrMember();
7365+
}
7366+
return false;
7367+
};
73627368
if (isa<TupleType>(desugar1) != isa<TupleType>(desugar2) &&
7363-
!desugar1->getOptionalObjectType() &&
7364-
!desugar2->getOptionalObjectType() &&
7369+
!isTypeVariableWrappedInOptional(desugar1) &&
7370+
!isTypeVariableWrappedInOptional(desugar2) &&
73657371
!desugar1->isAny() &&
73667372
!desugar2->isAny()) {
73677373
return matchTypes(

test/Constraints/variadic_generic_constraints.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,28 @@ func badCallToZip<each T, each U>(t: repeat each T, u: repeat each U) {
7777
// expected-error@-2 {{pack expansion requires that 'each U' and 'each T' have the same shape}}
7878
}
7979

80-
do {
81-
func test<A, B, each C>(
80+
func variadicGenericsInOptionalContext(v: Int?) {
81+
func test1<A, B, each C>(
8282
_: A,
8383
_: B,
8484
_: repeat each C
8585
) throws -> (A, B, repeat each C) {
8686
fatalError()
8787
}
8888

89+
func test2<A, B, each C>(
90+
_: A,
91+
_: B,
92+
_: (repeat each C)
93+
) throws -> (A, B, repeat each C) {
94+
fatalError()
95+
}
96+
8997
func test() {
90-
guard let _ = try? test(1, 2, 3) else { return } // Ok
98+
guard let _ = try? test1(1, 2, 3) else { return } // Ok
99+
guard let _ = try? test1(1, 2, v) else { return } // Ok
100+
101+
guard let _ = try? test2(1, 2, 3) else { return } // Ok
102+
guard let _ = try? test2(1, 2, v) else { return } // Ok
91103
}
92104
}

0 commit comments

Comments
 (0)