Allow existential opening for parameters of optional type.

This commit is contained in:
Doug Gregor
2022-02-10 17:56:07 -08:00
parent 5cf1cb368d
commit 761b0aa98c
3 changed files with 20 additions and 11 deletions

View File

@@ -1584,8 +1584,10 @@ shouldOpenExistentialCallArgument(
if (param->isVariadic())
return None;
// Look through an inout type on the formal type of the parameter.
auto formalParamTy = param->getInterfaceType()->getInOutObjectType();
// Look through an inout and optional types on the formal type of the
// parameter.
auto formalParamTy = param->getInterfaceType()->getInOutObjectType()
->lookThroughSingleOptionalType();
// If the argument is of an existential metatype, look through the
// metatype on the parameter.
@@ -1594,8 +1596,8 @@ shouldOpenExistentialCallArgument(
paramTy = paramTy->getMetatypeInstanceType();
}
// Look through an inout type on the parameter.
paramTy = paramTy->getInOutObjectType();
// Look through an inout and optional types on the parameter.
paramTy = paramTy->getInOutObjectType()->lookThroughSingleOptionalType();
// The parameter type must be a type variable.
auto paramTypeVar = paramTy->getAs<TypeVariableType>();