Skip to content

Commit 2ebade1

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.
1 parent b4ba68a commit 2ebade1

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
@@ -6514,6 +6514,17 @@ bool ConstraintSystem::repairFailures(
65146514
return !conversionsOrFixes.empty();
65156515
}
65166516

6517+
static bool isTupleWithUnresolvedPackExpansion(Type type) {
6518+
if (auto *tuple = type->getAs<TupleType>()) {
6519+
return llvm::any_of(tuple->getElements(), [&](const TupleTypeElt &elt) {
6520+
if (auto typeVar = elt.getType()->getAs<TypeVariableType>())
6521+
return typeVar->getImpl().isPackExpansion();
6522+
return false;
6523+
});
6524+
}
6525+
return false;
6526+
}
6527+
65176528
ConstraintSystem::TypeMatchResult
65186529
ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
65196530
TypeMatchOptions flags,
@@ -6781,6 +6792,12 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
67816792
return formUnsolvedResult();
67826793
}
67836794

6795+
// If either side is a tuple that has unresolved pack expansions,
6796+
// delay matching until more is inferred about type structure.
6797+
if (isTupleWithUnresolvedPackExpansion(desugar1) ||
6798+
isTupleWithUnresolvedPackExpansion(desugar2))
6799+
return formUnsolvedResult();
6800+
67846801
llvm::SmallVector<RestrictionOrFix, 4> conversionsOrFixes;
67856802

67866803
// Decompose parallel structure.

0 commit comments

Comments
 (0)