Skip to content

Commit 469ca59

Browse files
committed
Get copy init for tuple unpack assignment working
Signed-off-by: Anna Rift <[email protected]>
1 parent b50c2ec commit 469ca59

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

frontend/lib/resolution/call-init-deinit.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ void CallInitDeinit::resolveDefaultInit(const VarLikeDecl* ast, RV& rv) {
551551
}
552552
}
553553

554-
// Adjusts LHS tuple type so that its components are all references.
554+
// Adjusts LHS tuple type so that its components are all values.
555555
// Does no sanity checks.
556556
static QualifiedType
557557
getLhsForTupleUnpackAssign(Context* context,
@@ -576,7 +576,7 @@ getLhsForTupleUnpackAssign(Context* context,
576576
} else {
577577
// Otherwise, turn its qualifier into 'ref' / 'const ref'
578578
auto eqt = lhsT->elementType(i);
579-
auto kind = KindProperties::addRefness(eqt.kind());
579+
auto kind = KindProperties::removeRef(eqt.kind());
580580
qt = { kind, eqt.type(), eqt.param() };
581581
}
582582

@@ -596,6 +596,8 @@ void CallInitDeinit::resolveTupleUnpackAssign(const Tuple* lhsTuple,
596596
const QualifiedType& initialLhsType,
597597
const QualifiedType& rhsType,
598598
RV& rv) {
599+
VarFrame* frame = currentFrame();
600+
599601
// Make sure that both the LHS and RHS have types
600602
if (!initialLhsType.hasTypePtr()) {
601603
context->error(lhsTuple, "Unknown lhs tuple type in split tuple assign");
@@ -626,9 +628,6 @@ void CallInitDeinit::resolveTupleUnpackAssign(const Tuple* lhsTuple,
626628
return;
627629
}
628630

629-
// Then, make sure that the LHS is valid and adjust its intent.
630-
// It recomputes the LHS tuple type and sets it in 'byPostorder'.
631-
// It does not recompute intents for component sub-expressions.
632631
auto lhsType = getLhsForTupleUnpackAssign(context, astForErr, lhsTuple,
633632
initialLhsType);
634633
rv.byPostorder().byAst(lhsTuple).setType(lhsType);
@@ -651,7 +650,7 @@ void CallInitDeinit::resolveTupleUnpackAssign(const Tuple* lhsTuple,
651650
continue;
652651
}
653652

654-
resolveAssign(actual, lhsEltType, rhsEltType, rv);
653+
processInit(frame, actual, lhsEltType, rhsEltType, rv);
655654
}
656655
}
657656

frontend/test/resolution/testCallInitDeinit.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,9 +2034,9 @@ static void test31() {
20342034
{AssociatedAction::INIT_OTHER, "tup", ""},
20352035
{AssociatedAction::NEW_INIT, "M.test@12", ""},
20362036
{AssociatedAction::ASSIGN, "M.test@14", ""},
2037-
{AssociatedAction::COPY_INIT, "b", ""},
2038-
{AssociatedAction::DEINIT, "M.test@18", "r"},
2039-
{AssociatedAction::DEINIT, "M.test@18", "b"}
2037+
{AssociatedAction::COPY_INIT, "M.test@15", ""},
2038+
{AssociatedAction::DEINIT, "M.test@20", "b"},
2039+
{AssociatedAction::DEINIT, "M.test@20", "r"}
20402040
});
20412041
}
20422042

0 commit comments

Comments
 (0)