Skip to content

Commit af3b5e8

Browse files
committed
Sema: Clean up getMemberReferenceTypeFromOpenedType()
1 parent 6b2e598 commit af3b5e8

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

lib/Sema/CSApply.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,9 +2073,7 @@ namespace {
20732073

20742074
Type refTySelf = refTy, adjustedRefTySelf = adjustedRefTy;
20752075

2076-
auto *func = dyn_cast<FuncDecl>(member);
2077-
if (func && func->getResultInterfaceType()->hasDynamicSelfType()) {
2078-
ASSERT(refTy->hasDynamicSelfType());
2076+
if (refTy->hasDynamicSelfType()) {
20792077
refTySelf = refTy->replaceDynamicSelfType(containerTy);
20802078
adjustedRefTySelf = adjustedRefTy->replaceDynamicSelfType(
20812079
containerTy);
@@ -2177,11 +2175,8 @@ namespace {
21772175
const Type replacementTy = getDynamicSelfReplacementType(
21782176
baseTy, member, memberLocator.getBaseLocator());
21792177
if (!replacementTy->isEqual(containerTy)) {
2180-
if (isa<ConstructorDecl>(member)) {
2181-
adjustedRefTy = adjustedRefTy->withCovariantResultType();
2182-
} else {
2183-
ASSERT(adjustedRefTy->hasDynamicSelfType());
2184-
}
2178+
ASSERT(adjustedRefTy->hasDynamicSelfType());
2179+
21852180
Type conversionTy =
21862181
adjustedRefTy->replaceDynamicSelfType(replacementTy);
21872182
if (isSuperPartialApplication) {
@@ -2605,8 +2600,9 @@ namespace {
26052600

26062601
// Wrap in covariant `Self` return if needed.
26072602
if (ref.getDecl()->getDeclContext()->getSelfClassDecl()) {
2608-
auto covariantTy = resultTy->withCovariantResultType()
2609-
->replaceDynamicSelfType(cs.getType(base)->getWithoutSpecifierType());
2603+
ASSERT(resultTy->hasDynamicSelfType());
2604+
auto covariantTy = resultTy->replaceDynamicSelfType(
2605+
cs.getType(base)->getWithoutSpecifierType());
26102606
if (!covariantTy->isEqual(resultTy))
26112607
ctorRef = cs.cacheType(
26122608
new (ctx) CovariantFunctionConversionExpr(ctorRef, covariantTy));

lib/Sema/TypeOfReference.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,19 +1555,9 @@ Type ConstraintSystem::getMemberReferenceTypeFromOpenedType(
15551555
Type &openedType, Type baseObjTy, ValueDecl *value, DeclContext *outerDC,
15561556
ConstraintLocator *locator, bool hasAppliedSelf, bool isDynamicLookup,
15571557
ArrayRef<OpenedType> replacements) {
1558-
Type type = openedType;
1559-
1560-
// Cope with dynamic 'Self'.
15611558
if (outerDC->getSelfClassDecl()) {
15621559
if (isa<ConstructorDecl>(value)) {
1563-
type = type->withCovariantResultType();
1564-
}
1565-
1566-
if (type->hasDynamicSelfType()) {
1567-
auto replacementTy = getDynamicSelfReplacementType(
1568-
baseObjTy, value, locator);
1569-
1570-
type = type->replaceDynamicSelfType(replacementTy);
1560+
openedType = openedType->withCovariantResultType();
15711561
}
15721562
}
15731563

@@ -1593,13 +1583,19 @@ Type ConstraintSystem::getMemberReferenceTypeFromOpenedType(
15931583
fnTy->getExtInfo());
15941584
};
15951585

1596-
// FIXME: Refactor 'replaceCovariantResultType' not to rely on the passed
1597-
// uncurry level.
1598-
//
1599-
// This is done after handling dynamic 'Self' to make
1600-
// 'replaceCovariantResultType' work, so we have to transform both types.
16011586
openedType = applyOptionality(openedType->castTo<FunctionType>());
1602-
type = applyOptionality(type->castTo<FunctionType>());
1587+
}
1588+
}
1589+
1590+
Type type = openedType;
1591+
1592+
// Cope with dynamic 'Self'.
1593+
if (outerDC->getSelfClassDecl()) {
1594+
if (type->hasDynamicSelfType()) {
1595+
auto replacementTy = getDynamicSelfReplacementType(
1596+
baseObjTy, value, locator);
1597+
1598+
type = type->replaceDynamicSelfType(replacementTy);
16031599
}
16041600
}
16051601

0 commit comments

Comments
 (0)