Skip to content

Commit 391d64d

Browse files
committed
Switch tuple expression kind back to CONST_VAR
Signed-off-by: Anna Rift <[email protected]>
1 parent 3d03fe5 commit 391d64d

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ static bool isTypeParam(QualifiedType::Kind kind) {
187187
bool CallInitDeinit::isCallProducingValue(const AstNode* rhsAst,
188188
const QualifiedType& rhsType,
189189
RV& rv) {
190+
if (rhsAst->isTuple() && rhsType.type() && rhsType.type()->isTupleType()) {
191+
if (auto asTupleType = rhsType.type()->toTupleType()) {
192+
// Consider a tuple expression to be a call producing a value (for the
193+
// purposes of call-init-deinit) iff it contains only value elements.
194+
return asTupleType == asTupleType->toValueTuple(context);
195+
}
196+
}
197+
190198
return rv.byAst(rhsAst).toId().isEmpty() && !isRef(rhsType.kind());
191199
}
192200

frontend/lib/resolution/resolution-queries.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5811,12 +5811,8 @@ CallResolutionResult resolveTupleExpr(Context* context,
58115811
kind = QualifiedType::TYPE;
58125812
t = TupleType::getValueTuple(context, std::move(eltTypes));
58135813
} else if (allValue) {
5814-
kind = QualifiedType::CONST_REF;
5814+
kind = QualifiedType::CONST_VAR;
58155815
t = TupleType::getReferentialTuple(context, std::move(eltTypes));
5816-
// Use CONST_VAR intent for tuple expressions containing no references
5817-
if (t->toTupleType()->toValueTuple(context) == t->toTupleType()) {
5818-
kind = QualifiedType::CONST_VAR;
5819-
}
58205816
} else {
58215817
context->error(tuple, "Mix of value and type tuple elements in tuple expr");
58225818
kind = QualifiedType::UNKNOWN;

frontend/test/resolution/testTuples.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void test3() {
8787
var x = (r, r);
8888
)"""");
8989

90-
assert(qt.kind() == QualifiedType::CONST_REF);
90+
assert(qt.kind() == QualifiedType::CONST_VAR);
9191
assert(qt.type()->isTupleType());
9292
auto tt = qt.type()->toTupleType();
9393
assert(tt->numElements() == 2);

0 commit comments

Comments
 (0)