Skip to content

Commit cb9aaaa

Browse files
authored
Merge pull request #60108 from DougGregor/existential-var-opening-5.7
2 parents 3a67c1a + 5957122 commit cb9aaaa

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5929,7 +5929,7 @@ ArgumentList *ExprRewriter::coerceCallArguments(
59295929

59305930
// If the argument is an existential type that has been opened, perform
59315931
// the open operation.
5932-
if (argType->getInOutObjectType()->isAnyExistentialType() &&
5932+
if (argType->getWithoutSpecifierType()->isAnyExistentialType() &&
59335933
paramType->hasOpenedExistential()) {
59345934
// FIXME: Look for an opened existential and use it. We need to
59355935
// know how far out we need to go to close the existentials. Huh.

lib/Sema/CSSimplify.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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,6 +1542,12 @@ 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();
@@ -1946,6 +1953,9 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
19461953
std::tie(argTy, opened) = cs.openExistentialType(
19471954
existentialType, cs.getConstraintLocator(loc));
19481955

1956+
if (adjustments.contains(OpenedExistentialAdjustmentFlags::LValue))
1957+
argTy = LValueType::get(argTy);
1958+
19491959
if (adjustments.contains(OpenedExistentialAdjustmentFlags::InOut))
19501960
argTy = InOutType::get(argTy);
19511961

test/Constraints/opened_existentials.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ func testSimpleExistentialOpening(p: any P, pq: any P & Q, c: any Collection) {
2525
let pa = acceptGeneric(p)
2626
let _: Int = pa // expected-error{{cannot convert value of type '(any Q)?' to specified type 'Int'}}
2727

28+
var vp = p
29+
let vpa = acceptGeneric(vp)
30+
let _: Int = vpa // expected-error{{cannot convert value of type '(any Q)?' to specified type 'Int'}}
31+
2832
let pqa = acceptGeneric(pq)
2933
let _: Int = pqa // expected-error{{cannot convert value of type '(any Q)?' to specified type 'Int'}}
3034

0 commit comments

Comments
 (0)