mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[NFC] Sema: Tidy up canOpenExistentialCallArgument
This commit is contained in:
@@ -1441,8 +1441,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
static std::optional<
|
||||
std::tuple<TypeVariableType *, Type, OpenedExistentialAdjustments>>
|
||||
static std::optional<std::pair<TypeVariableType *, Type>>
|
||||
shouldOpenExistentialCallArgument(ValueDecl *callee, unsigned paramIdx,
|
||||
Type paramTy, Type argTy, Expr *argExpr,
|
||||
ConstraintSystem &cs) {
|
||||
@@ -1816,25 +1815,29 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
|
||||
|
||||
// If the argument is an existential type and the parameter is generic,
|
||||
// consider opening the existential type.
|
||||
if (auto existentialArg = shouldOpenExistentialCallArgument(
|
||||
if (auto typeVarAndBindingTy = shouldOpenExistentialCallArgument(
|
||||
callee, paramIdx, paramTy, argTy, argExpr, cs)) {
|
||||
// My kingdom for a decent "if let" in C++.
|
||||
TypeVariableType *openedTypeVar;
|
||||
Type existentialType;
|
||||
OpenedExistentialAdjustments adjustments;
|
||||
std::tie(openedTypeVar, existentialType, adjustments) = *existentialArg;
|
||||
TypeVariableType *typeVar;
|
||||
Type bindingTy;
|
||||
std::tie(typeVar, bindingTy) = *typeVarAndBindingTy;
|
||||
|
||||
OpenedArchetypeType *opened;
|
||||
std::tie(argTy, opened) = cs.openAnyExistentialType(
|
||||
existentialType, cs.getConstraintLocator(loc));
|
||||
OpenedArchetypeType *openedArchetype;
|
||||
|
||||
if (adjustments.contains(OpenedExistentialAdjustmentFlags::LValue))
|
||||
argTy = LValueType::get(argTy);
|
||||
// Open the argument type.
|
||||
argTy = argTy.transformRec([&](TypeBase *t) -> std::optional<Type> {
|
||||
if (t->isAnyExistentialType()) {
|
||||
Type openedTy;
|
||||
std::tie(openedTy, openedArchetype) =
|
||||
cs.openAnyExistentialType(t, cs.getConstraintLocator(loc));
|
||||
|
||||
if (adjustments.contains(OpenedExistentialAdjustmentFlags::InOut))
|
||||
argTy = InOutType::get(argTy);
|
||||
return openedTy;
|
||||
}
|
||||
|
||||
openedExistentials.push_back({openedTypeVar, opened});
|
||||
return std::nullopt;
|
||||
});
|
||||
|
||||
openedExistentials.push_back({typeVar, openedArchetype});
|
||||
}
|
||||
|
||||
// If we have a compound function reference (e.g `fn($x:)`), respect
|
||||
|
||||
Reference in New Issue
Block a user