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

@@ -2578,6 +2578,7 @@ Type ConstraintSystem::getEffectiveOverloadType(ConstraintLocator *locator,
case OverloadChoiceKind::KeyPathDynamicMemberLookup:
case OverloadChoiceKind::KeyPathApplication:
case OverloadChoiceKind::TupleIndex:
case OverloadChoiceKind::MaterializePack:
return Type();
}
@@ -3262,6 +3263,7 @@ void ConstraintSystem::bindOverloadType(
case OverloadChoiceKind::DeclViaBridge:
case OverloadChoiceKind::DeclViaUnwrappedOptional:
case OverloadChoiceKind::TupleIndex:
case OverloadChoiceKind::MaterializePack:
case OverloadChoiceKind::KeyPathApplication:
bindTypeOrIUO(openedType);
return;
@@ -3503,6 +3505,14 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
refType = adjustedRefType;
break;
case OverloadChoiceKind::MaterializePack: {
auto *tuple = choice.getBaseType()->castTo<TupleType>();
auto *expansion = tuple->getElementType(0)->castTo<PackExpansionType>();
adjustedRefType = expansion->getPatternType();
refType = adjustedRefType;
break;
}
case OverloadChoiceKind::KeyPathApplication: {
// Key path application looks like a subscript(keyPath: KeyPath<Base, T>).
// The element type is T or @lvalue T based on the key path subtype and
@@ -3965,6 +3975,7 @@ DeclName OverloadChoice::getName() const {
case OverloadChoiceKind::KeyPathDynamicMemberLookup:
return DeclName(DynamicMember.getPointer());
case OverloadChoiceKind::MaterializePack:
case OverloadChoiceKind::TupleIndex:
llvm_unreachable("no name!");
}
@@ -5261,6 +5272,7 @@ bool ConstraintSystem::diagnoseAmbiguity(ArrayRef<Solution> solutions) {
break;
case OverloadChoiceKind::TupleIndex:
case OverloadChoiceKind::MaterializePack:
// FIXME: Actually diagnose something here.
break;
}