Skip to content

Commit e6d434a

Browse files
committed
[CSSimplify] Delay matching if one of the types is a tuple with unresolved pack expansions
This handles situations like `Int <conv> (Int, (_: $T_exp)` or `String arg conv (_: $T_exp)`. The matching has to be delayed because the structure of the tuple type is not known until `$T_exp` (which represents a pack expansion type) is resolved. (cherry picked from commit 2ebade1)
1 parent dda8910 commit e6d434a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6518,6 +6518,17 @@ bool ConstraintSystem::repairFailures(
65186518
return !conversionsOrFixes.empty();
65196519
}
65206520

6521+
static bool isTupleWithUnresolvedPackExpansion(Type type) {
6522+
if (auto *tuple = type->getAs<TupleType>()) {
6523+
return llvm::any_of(tuple->getElements(), [&](const TupleTypeElt &elt) {
6524+
if (auto typeVar = elt.getType()->getAs<TypeVariableType>())
6525+
return typeVar->getImpl().isPackExpansion();
6526+
return false;
6527+
});
6528+
}
6529+
return false;
6530+
}
6531+
65216532
ConstraintSystem::TypeMatchResult
65226533
ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
65236534
TypeMatchOptions flags,
@@ -6785,6 +6796,12 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
67856796
return formUnsolvedResult();
67866797
}
67876798

6799+
// If either side is a tuple that has unresolved pack expansions,
6800+
// delay matching until more is inferred about type structure.
6801+
if (isTupleWithUnresolvedPackExpansion(desugar1) ||
6802+
isTupleWithUnresolvedPackExpansion(desugar2))
6803+
return formUnsolvedResult();
6804+
67886805
llvm::SmallVector<RestrictionOrFix, 4> conversionsOrFixes;
67896806

67906807
// Decompose parallel structure.

0 commit comments

Comments
 (0)