Skip to content

Commit 2191f37

Browse files
committed
[CSApply] NFC: Simplify coerceSelfArgumentToType
`coerceToType` can to handle l-value -> inout correctly and report better information if coercion fails. (cherry picked from commit c225db4)
1 parent 28d1cf9 commit 2191f37

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7980,26 +7980,7 @@ ExprRewriter::coerceSelfArgumentToType(Expr *expr,
79807980
Type baseTy, ValueDecl *member,
79817981
ConstraintLocatorBuilder locator) {
79827982
Type toType = adjustSelfTypeForMember(expr, baseTy, member, dc);
7983-
7984-
// If our expression already has the right type, we're done.
7985-
Type fromType = cs.getType(expr);
7986-
if (fromType->isEqual(toType))
7987-
return expr;
7988-
7989-
// If we're coercing to an rvalue type, just do it.
7990-
auto toInOutTy = toType->getAs<InOutType>();
7991-
if (!toInOutTy)
7992-
return coerceToType(expr, toType, locator);
7993-
7994-
assert(fromType->is<LValueType>() && "Can only convert lvalues to inout");
7995-
7996-
auto &ctx = cs.getASTContext();
7997-
7998-
// Use InOutExpr to convert it to an explicit inout argument for the
7999-
// receiver.
8000-
return cs.cacheType(new (ctx) InOutExpr(expr->getStartLoc(), expr,
8001-
toInOutTy->getInOutObjectType(),
8002-
/*isImplicit*/ true));
7983+
return coerceToType(expr, toType, locator);
80037984
}
80047985

80057986
Expr *ExprRewriter::convertLiteralInPlace(

0 commit comments

Comments
 (0)