Merge pull request #63991 from hborla/materialize-pack-from-tuple

[ConstraintSystem] Implement type checking for converting a tuple to a pack using the `.element` syntax.
This commit is contained in:
Holly Borla
2023-03-01 16:19:33 -08:00
committed by GitHub
17 changed files with 148 additions and 0 deletions

View File

@@ -154,6 +154,7 @@ static bool areConservativelyCompatibleArgumentLabels(
case OverloadChoiceKind::DynamicMemberLookup:
case OverloadChoiceKind::KeyPathDynamicMemberLookup:
case OverloadChoiceKind::TupleIndex:
case OverloadChoiceKind::MaterializePack:
return true;
}
@@ -8980,6 +8981,15 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
if (auto baseTuple = baseObjTy->getAs<TupleType>()) {
if (!memberName.isSpecial()) {
StringRef nameStr = memberName.getBaseIdentifier().str();
// Accessing `.element` on an abstract tuple materializes a pack.
if (nameStr == "element" && baseTuple->getNumElements() == 1 &&
baseTuple->getElementType(0)->is<PackExpansionType>()) {
result.ViableCandidates.push_back(
OverloadChoice(baseTy, OverloadChoiceKind::MaterializePack));
return result;
}
int fieldIdx = -1;
// Resolve a number reference into the tuple type.
unsigned Value = 0;