@@ -1468,6 +1468,7 @@ namespace {
14681468 enum class OpenedExistentialAdjustmentFlags {
14691469 /// The argument should be made inout after opening.
14701470 InOut = 0x01,
1471+ LValue = 0x02,
14711472 };
14721473
14731474 using OpenedExistentialAdjustments =
@@ -1541,16 +1542,18 @@ shouldOpenExistentialCallArgument(
15411542
15421543 OpenedExistentialAdjustments adjustments;
15431544
1545+ // The argument may be a "var" instead of a "let".
1546+ if (auto lv = argTy->getAs<LValueType>()) {
1547+ argTy = lv->getObjectType();
1548+ adjustments |= OpenedExistentialAdjustmentFlags::LValue;
1549+ }
1550+
15441551 // If the argument is inout, strip it off and we can add it back.
15451552 if (auto inOutArg = argTy->getAs<InOutType>()) {
15461553 argTy = inOutArg->getObjectType();
15471554 adjustments |= OpenedExistentialAdjustmentFlags::InOut;
15481555 }
15491556
1550- // The argument may be a "var" instead of a "let".
1551- if (auto lv = dyn_cast<LValueType>(argTy->getCanonicalType()))
1552- argTy = lv->getObjectType();
1553-
15541557 // The argument type needs to be an existential type or metatype thereof.
15551558 if (!argTy->isAnyExistentialType())
15561559 return None;
@@ -1948,6 +1951,9 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
19481951 std::tie(argTy, opened) = cs.openExistentialType(
19491952 existentialType, cs.getConstraintLocator(loc));
19501953
1954+ if (adjustments.contains(OpenedExistentialAdjustmentFlags::LValue))
1955+ argTy = LValueType::get(argTy);
1956+
19511957 if (adjustments.contains(OpenedExistentialAdjustmentFlags::InOut))
19521958 argTy = InOutType::get(argTy);
19531959
0 commit comments