Skip to content

Commit ab81406

Browse files
committed
Sema: Use coerceToRValue() to load tuples of lvalues instead of coerceTupleToTuple()
1 parent 18e8fea commit ab81406

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

lib/Sema/CSApply.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5259,13 +5259,7 @@ Expr *ExprRewriter::coerceExistential(Expr *expr, Type toType,
52595259
// Load tuples with lvalue elements.
52605260
if (auto tupleType = fromType->getAs<TupleType>()) {
52615261
if (tupleType->hasLValueType()) {
5262-
auto toTuple = tupleType->getRValueType()->castTo<TupleType>();
5263-
SmallVector<unsigned, 4> sources;
5264-
bool failed = computeTupleShuffle(tupleType, toTuple, sources);
5265-
assert(!failed && "Couldn't convert tuple to tuple?");
5266-
(void)failed;
5267-
5268-
coerceTupleToTuple(expr, tupleType, toTuple, locator, sources);
5262+
expr = cs.coerceToRValue(expr);
52695263
}
52705264
}
52715265

@@ -6492,6 +6486,10 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
64926486
auto toTuple = toType->getAs<TupleType>();
64936487
if (!toTuple)
64946488
break;
6489+
6490+
if (fromTuple->hasLValueType() && !toTuple->hasLValueType())
6491+
return coerceToType(cs.coerceToRValue(expr), toType, locator);
6492+
64956493
SmallVector<unsigned, 4> sources;
64966494
if (!computeTupleShuffle(fromTuple, toTuple, sources)) {
64976495
return coerceTupleToTuple(expr, fromTuple, toTuple,

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,15 +3134,11 @@ Expr *TypeChecker::coerceToRValue(Expr *expr,
31343134
return FVE;
31353135
}
31363136

3137-
// Load lvalues.
3138-
if (exprTy->is<LValueType>())
3139-
return addImplicitLoadExpr(expr, getType, setType);
3140-
31413137
// Walk into parenthesized expressions to update the subexpression.
31423138
if (auto paren = dyn_cast<IdentityExpr>(expr)) {
31433139
auto sub = coerceToRValue(paren->getSubExpr(), getType, setType);
31443140
paren->setSubExpr(sub);
3145-
setType(paren, getType(sub));
3141+
setType(paren, ParenType::get(Context, getType(sub)));
31463142
return paren;
31473143
}
31483144

@@ -3186,6 +3182,10 @@ Expr *TypeChecker::coerceToRValue(Expr *expr,
31863182
return tuple;
31873183
}
31883184

3185+
// Load lvalues.
3186+
if (exprTy->is<LValueType>())
3187+
return addImplicitLoadExpr(expr, getType, setType);
3188+
31893189
// Nothing to do.
31903190
return expr;
31913191
}

0 commit comments

Comments
 (0)