@@ -1403,23 +1403,25 @@ namespace {
1403
1403
// special handling.
1404
1404
if (baseExpr) {
1405
1405
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
+ }
1419
1420
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
+ }
1423
1425
}
1424
1426
}
1425
1427
}
@@ -2111,10 +2113,9 @@ namespace {
2111
2113
//
2112
2114
// Note: For unbound references this is handled inside the thunk.
2113
2115
if (!isUnboundInstanceMember &&
2114
- ! member->getDeclContext ()->getSelfProtocolDecl ()) {
2116
+ member->getDeclContext ()->getSelfClassDecl ()) {
2115
2117
if (auto func = dyn_cast<AbstractFunctionDecl>(member)) {
2116
- if (func->hasDynamicSelfResult () &&
2117
- !baseTy->getOptionalObjectType ()) {
2118
+ if (func->hasDynamicSelfResult ()) {
2118
2119
// FIXME: Once CovariantReturnConversionExpr (unchecked_ref_cast)
2119
2120
// supports a class existential dest., consider using the opened
2120
2121
// type directly to avoid recomputing the 'Self' replacement and
0 commit comments