Skip to content

Commit 0999792

Browse files
authored
Merge pull request #82467 from xedin/swift-testing-troubles
[CSSimplify] Narrow down tuple wrapping for pack expansion matching
2 parents ce7a3b3 + 4804f21 commit 0999792

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7358,11 +7358,16 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
73587358
// and `Optional<T>` which would be handled by optional injection.
73597359
if (isTupleWithUnresolvedPackExpansion(origType1) ||
73607360
isTupleWithUnresolvedPackExpansion(origType2)) {
7361+
auto isTypeVariableWrappedInOptional = [](Type type) {
7362+
if (type->getOptionalObjectType()) {
7363+
return type->lookThroughAllOptionalTypes()->isTypeVariableOrMember();
7364+
}
7365+
return false;
7366+
};
73617367
if (isa<TupleType>(desugar1) != isa<TupleType>(desugar2) &&
7362-
!isa<InOutType>(desugar1) &&
7363-
!isa<InOutType>(desugar2) &&
7364-
!desugar1->getOptionalObjectType() &&
7365-
!desugar2->getOptionalObjectType() &&
7368+
!isa<InOutType>(desugar1) && !isa<InOutType>(desugar2) &&
7369+
!isTypeVariableWrappedInOptional(desugar1) &&
7370+
!isTypeVariableWrappedInOptional(desugar2) &&
73667371
!desugar1->isAny() &&
73677372
!desugar2->isAny()) {
73687373
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)