mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user