Allow Converting Pack Types to Tuples

Insert an implicit conversion from pack types to tuples with equivalent parallel structure. That means

1) The tuple must have the same arity
2) The tuple may not have any argument labels
3) The tuple may not have any variadic or inout components
4) The tuple must have the same element types as the pack
This commit is contained in:
Robert Widmann
2021-12-16 01:15:19 -08:00
parent 0471e2c58e
commit d44d8ec043
8 changed files with 53 additions and 1 deletions

View File

@@ -11630,6 +11630,22 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
{getConstraintLocator(locator), restriction});
return SolutionKind::Solved;
}
case ConversionRestrictionKind::ReifyPackToType: {
type1 = simplifyType(type1);
auto *PET = type1->castTo<PackType>();
if (auto *TT = type2->getAs<TupleType>()) {
llvm::SmallVector<TupleTypeElt, 8> elts;
for (Type elt : PET->getElementTypes()) {
elts.push_back(elt);
}
Type tupleType1 = TupleType::get(elts, getASTContext());
return matchTypes(tupleType1, TT, ConstraintKind::Bind, subflags,
locator);
} else {
return matchTypes(PET->getElementType(0), type2, ConstraintKind::Bind,
subflags, locator);
}
}
}
llvm_unreachable("bad conversion restriction");