Skip to content

Commit 8744e8a

Browse files
committed
Sema: Sink ModuleDecl handling back down into getTypeOfMemberReferencePre/Post()
1 parent a12c160 commit 8744e8a

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

lib/Sema/TypeOfReference.cpp

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,6 +1883,10 @@ ConstraintSystem::getTypeOfMemberReferencePre(
18831883
Type baseRValueTy = baseTy->getRValueType();
18841884
auto baseObjTy = baseRValueTy->getMetatypeInstanceType();
18851885

1886+
if (baseObjTy->is<ModuleType>()) {
1887+
return getTypeOfReferencePre(choice, useDC, locator, preparedOverload);
1888+
}
1889+
18861890
Type openedType;
18871891
Type thrownErrorType;
18881892

@@ -2048,19 +2052,20 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReferencePost(
20482052
Type openedType, Type thrownErrorType) {
20492053
auto *value = choice.getDecl();
20502054

2051-
if (isa<TypeDecl>(value)) {
2052-
auto type = openedType->castTo<FunctionType>()->getResult();
2053-
return { openedType, openedType, type, type, Type() };
2054-
}
2055-
20562055
// Figure out the instance type used for the base.
20572056
Type baseTy = choice.getBaseType();
20582057
Type baseRValueTy = baseTy->getRValueType();
20592058
Type baseObjTy = baseRValueTy->getMetatypeInstanceType();
20602059

2061-
// A reference to a module member is really unqualified, and should
2062-
// be handled by the caller via getTypeOfReference().
2063-
ASSERT(!baseObjTy->is<ModuleType>());
2060+
if (baseObjTy->is<ModuleType>()) {
2061+
return getTypeOfReferencePost(choice, useDC, locator,
2062+
openedType, thrownErrorType);
2063+
}
2064+
2065+
if (isa<TypeDecl>(value)) {
2066+
auto type = openedType->castTo<FunctionType>()->getResult();
2067+
return { openedType, openedType, type, type, Type() };
2068+
}
20642069

20652070
auto hasAppliedSelf = doesMemberRefApplyCurriedSelf(baseRValueTy, value);
20662071

@@ -2854,15 +2859,7 @@ ConstraintSystem::prepareOverloadImpl(OverloadChoice choice,
28542859
auto openedType = getTypeOfReferenceWithSpecialTypeCheckingSemantics(
28552860
*this, locator, semantics, preparedOverload);
28562861
return {openedType, Type()};
2857-
} else if (auto baseTy = choice.getBaseType()) {
2858-
// Retrieve the type of a reference to the specific declaration choice.
2859-
assert(!baseTy->hasTypeParameter());
2860-
2861-
// If the base is a module type, it's an unqualified reference.
2862-
if (baseTy->getMetatypeInstanceType()->is<ModuleType>()) {
2863-
return getTypeOfReferencePre(choice, useDC, locator, preparedOverload);
2864-
}
2865-
2862+
} else if (choice.getBaseType()) {
28662863
return getTypeOfMemberReferencePre(choice, useDC, locator, preparedOverload);
28672864
} else {
28682865
return getTypeOfReferencePre(choice, useDC, locator, preparedOverload);
@@ -2926,15 +2923,9 @@ void ConstraintSystem::resolveOverload(OverloadChoice choice, DeclContext *useDC
29262923
} else {
29272924
DeclReferenceType declRefType;
29282925

2929-
if (auto baseTy = choice.getBaseType()) {
2930-
// If the base is a module type, it's an unqualified reference.
2931-
if (baseTy->getMetatypeInstanceType()->is<ModuleType>()) {
2932-
declRefType = getTypeOfReferencePost(
2933-
choice, useDC, locator, openedType, thrownErrorType);
2934-
} else {
2935-
declRefType = getTypeOfMemberReferencePost(
2936-
choice, useDC, locator, openedType, thrownErrorType);
2937-
}
2926+
if (choice.getBaseType()) {
2927+
declRefType = getTypeOfMemberReferencePost(
2928+
choice, useDC, locator, openedType, thrownErrorType);
29382929
} else {
29392930
declRefType = getTypeOfReferencePost(
29402931
choice, useDC, locator, openedType, thrownErrorType);

0 commit comments

Comments
 (0)