Skip to content

Commit 2be16b8

Browse files
committed
[CSSimplify] Delay matching tuple types with unresolved pack expansions followed
by an unlabeled element until pack type variables are resolved.
1 parent 4202079 commit 2be16b8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6575,6 +6575,42 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
65756575
}
65766576

65776577
case TypeKind::Tuple: {
6578+
// FIXME: TuplePackMatcher doesn't correctly handle matching two
6579+
// abstract contextual tuple types in a generic context.
6580+
if (simplifyType(desugar1)->isEqual(simplifyType(desugar2)))
6581+
return getTypeMatchSuccess();
6582+
6583+
// If the tuple has consecutive pack expansions, packs must be
6584+
// resolved before matching.
6585+
auto delayMatching = [](TupleType *tuple) {
6586+
bool afterUnresolvedPack = false;
6587+
for (auto element : tuple->getElements()) {
6588+
if (afterUnresolvedPack && !element.hasName()) {
6589+
return true;
6590+
}
6591+
6592+
if (element.getType()->is<PackExpansionType>()) {
6593+
SmallPtrSet<TypeVariableType *, 2> typeVars;
6594+
element.getType()->getTypeVariables(typeVars);
6595+
6596+
afterUnresolvedPack = llvm::any_of(typeVars, [](auto *tv) {
6597+
return tv->getImpl().canBindToPack();
6598+
});
6599+
} else {
6600+
afterUnresolvedPack = false;
6601+
}
6602+
}
6603+
6604+
return false;
6605+
};
6606+
6607+
6608+
auto *tuple1 = cast<TupleType>(desugar1);
6609+
auto *tuple2 = cast<TupleType>(desugar2);
6610+
if (delayMatching(tuple1) || delayMatching(tuple2)) {
6611+
return formUnsolvedResult();
6612+
}
6613+
65786614
// Add each tuple type to the locator before matching the element types.
65796615
// This is useful for diagnostics, because the error message can use the
65806616
// full tuple type for several element mismatches. Use the original types

0 commit comments

Comments
 (0)