Skip to content

Commit a7d12e7

Browse files
committed
Sema: Small CSApply cleanup
1 parent 1716832 commit a7d12e7

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

lib/Sema/CSApply.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,23 +1403,25 @@ namespace {
14031403
// special handling.
14041404
if (baseExpr) {
14051405
if (auto *fnDecl = dyn_cast<AbstractFunctionDecl>(declOrClosure)) {
1406-
if (fnDecl->hasDynamicSelfResult()) {
1407-
Type convTy;
1408-
1409-
if (cs.getType(baseExpr)->hasOpenedExistential()) {
1410-
// FIXME: Sometimes we need to convert to an opened existential
1411-
// first, because CovariantReturnConversionExpr does not support
1412-
// direct conversions from a class C to an existential C & P.
1413-
convTy = cs.getType(baseExpr)->getMetatypeInstanceType();
1414-
if (thunkTy->getResult()->getOptionalObjectType())
1415-
convTy = OptionalType::get(thunkTy);
1416-
} else {
1417-
convTy = thunkTy->getResult();
1418-
}
1406+
if (fnDecl->getDeclContext()->getSelfClassDecl()) {
1407+
if (fnDecl->hasDynamicSelfResult()) {
1408+
Type convTy;
1409+
1410+
if (cs.getType(baseExpr)->hasOpenedExistential()) {
1411+
// FIXME: Sometimes we need to convert to an opened existential
1412+
// first, because CovariantReturnConversionExpr does not support
1413+
// direct conversions from a class C to an existential C & P.
1414+
convTy = cs.getType(baseExpr)->getMetatypeInstanceType();
1415+
if (thunkTy->getResult()->getOptionalObjectType())
1416+
convTy = OptionalType::get(thunkTy);
1417+
} else {
1418+
convTy = thunkTy->getResult();
1419+
}
14191420

1420-
if (!thunkBody->getType()->isEqual(convTy)) {
1421-
thunkBody = cs.cacheType(
1422-
new (ctx) CovariantReturnConversionExpr(thunkBody, convTy));
1421+
if (!thunkBody->getType()->isEqual(convTy)) {
1422+
thunkBody = cs.cacheType(
1423+
new (ctx) CovariantReturnConversionExpr(thunkBody, convTy));
1424+
}
14231425
}
14241426
}
14251427
}
@@ -2111,10 +2113,9 @@ namespace {
21112113
//
21122114
// Note: For unbound references this is handled inside the thunk.
21132115
if (!isUnboundInstanceMember &&
2114-
!member->getDeclContext()->getSelfProtocolDecl()) {
2116+
member->getDeclContext()->getSelfClassDecl()) {
21152117
if (auto func = dyn_cast<AbstractFunctionDecl>(member)) {
2116-
if (func->hasDynamicSelfResult() &&
2117-
!baseTy->getOptionalObjectType()) {
2118+
if (func->hasDynamicSelfResult()) {
21182119
// FIXME: Once CovariantReturnConversionExpr (unchecked_ref_cast)
21192120
// supports a class existential dest., consider using the opened
21202121
// type directly to avoid recomputing the 'Self' replacement and

0 commit comments

Comments
 (0)