Skip to content

Commit fc4b85e

Browse files
committed
Sema: Maintain adjusted/original distinction in getTypeOfReference()
1 parent e8ec5be commit fc4b85e

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

lib/Sema/TypeOfReference.cpp

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,16 +1008,6 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
10081008
// If we opened up any type variables, record the replacements.
10091009
recordOpenedTypes(locator, replacements, preparedOverload);
10101010

1011-
// If this is a method whose result type is dynamic Self, replace
1012-
// DynamicSelf with the actual object type.
1013-
if (openedType->hasDynamicSelfType()) {
1014-
auto params = openedType->getParams();
1015-
assert(params.size() == 1);
1016-
Type selfTy = params.front().getPlainType()->getMetatypeInstanceType();
1017-
openedType = openedType->replaceDynamicSelfType(selfTy)
1018-
->castTo<FunctionType>();
1019-
}
1020-
10211011
auto origOpenedType = openedType;
10221012
if (!isRequirementOrWitness(locator)) {
10231013
unsigned numApplies = getNumApplications(/*hasAppliedSelf*/ false,
@@ -1027,9 +1017,30 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
10271017
replacements, locator, preparedOverload);
10281018
}
10291019

1020+
// If this is a method whose result type is dynamic Self, replace
1021+
// DynamicSelf with the actual object type. Repeat the adjustment
1022+
// for the original and adjusted types.
1023+
auto type = openedType;
1024+
if (openedType->hasDynamicSelfType()) {
1025+
auto params = openedType->getParams();
1026+
assert(params.size() == 1);
1027+
Type selfTy = params.front().getPlainType()->getMetatypeInstanceType();
1028+
type = openedType->replaceDynamicSelfType(selfTy)
1029+
->castTo<FunctionType>();
1030+
}
1031+
1032+
auto origType = origOpenedType;
1033+
if (origOpenedType->hasDynamicSelfType()) {
1034+
auto params = origOpenedType->getParams();
1035+
assert(params.size() == 1);
1036+
Type selfTy = params.front().getPlainType()->getMetatypeInstanceType();
1037+
origType = origOpenedType->replaceDynamicSelfType(selfTy)
1038+
->castTo<FunctionType>();
1039+
}
1040+
10301041
// The reference implicitly binds 'self'.
10311042
return {origOpenedType, openedType,
1032-
origOpenedType->getResult(), openedType->getResult(), Type()};
1043+
origType->getResult(), type->getResult(), Type()};
10331044
}
10341045

10351046
// Unqualified reference to a local or global function.

0 commit comments

Comments
 (0)