@@ -1109,11 +1109,12 @@ recordFixIfNeededForPlaceholderInDecl(ConstraintSystem &cs, ValueDecl *D,
11091109}
11101110
11111111std::pair<Type, Type>
1112- ConstraintSystem::getTypeOfReferenceImpl (ValueDecl *value,
1113- FunctionRefInfo functionRefInfo,
1112+ ConstraintSystem::getTypeOfReferenceImpl (OverloadChoice choice,
11141113 ConstraintLocatorBuilder locator,
11151114 DeclContext *useDC,
11161115 PreparedOverloadBuilder *preparedOverload) {
1116+ auto *value = choice.getDecl ();
1117+
11171118 ASSERT (!!preparedOverload == PreparingOverload);
11181119
11191120 recordFixIfNeededForPlaceholderInDecl (*this , value, locator);
@@ -1139,6 +1140,8 @@ ConstraintSystem::getTypeOfReferenceImpl(ValueDecl *value,
11391140
11401141 // Unqualified reference to a local or global function.
11411142 if (auto funcDecl = dyn_cast<AbstractFunctionDecl>(value)) {
1143+ auto functionRefInfo = choice.getFunctionRefInfo ();
1144+
11421145 SmallVector<OpenedType, 4 > replacements;
11431146
11441147 auto funcType = funcDecl->getInterfaceType ()->castTo <AnyFunctionType>();
@@ -1234,16 +1237,17 @@ ConstraintSystem::getTypeOfReferenceImpl(ValueDecl *value,
12341237}
12351238
12361239DeclReferenceType
1237- ConstraintSystem::getTypeOfReference (ValueDecl *value,
1238- FunctionRefInfo functionRefInfo,
1240+ ConstraintSystem::getTypeOfReference (OverloadChoice choice,
12391241 ConstraintLocatorBuilder locator,
12401242 DeclContext *useDC,
12411243 PreparedOverloadBuilder *preparedOverload) {
12421244 ASSERT (!!preparedOverload == PreparingOverload);
12431245
12441246 Type openedType, thrownErrorType;
12451247 std::tie (openedType, thrownErrorType) = getTypeOfReferenceImpl (
1246- value, functionRefInfo, locator, useDC, preparedOverload);
1248+ choice, locator, useDC, preparedOverload);
1249+
1250+ auto *value = choice.getDecl ();
12471251
12481252 if (value->getDeclContext ()->isTypeContext () && isa<FuncDecl>(value)) {
12491253 auto *openedFnType = openedType->castTo <FunctionType>();
@@ -1252,6 +1256,7 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
12521256 auto func = cast<FuncDecl>(value);
12531257 assert (func->isOperator () && " Lookup should only find operators" );
12541258
1259+ auto functionRefInfo = choice.getFunctionRefInfo ();
12551260
12561261 auto origOpenedType = openedFnType;
12571262 if (!isRequirementOrWitness (locator)) {
@@ -1293,7 +1298,7 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
12931298 auto origOpenedType = openedType;
12941299 if (!isRequirementOrWitness (locator)) {
12951300 unsigned numApplies = getNumApplications (/* hasAppliedSelf*/ false ,
1296- functionRefInfo );
1301+ choice. getFunctionRefInfo () );
12971302 openedType = adjustFunctionTypeForConcurrency (
12981303 origOpenedType->castTo <FunctionType>(), /* baseType=*/ Type (), funcDecl,
12991304 useDC, numApplies, /* isMainDispatchQueue=*/ false ,
@@ -1523,10 +1528,10 @@ void ConstraintSystem::openGenericRequirement(
15231528 preparedOverload);
15241529}
15251530
1526- DeclReferenceType ConstraintSystem::getTypeOfMemberTypeReference (
1531+ Type ConstraintSystem::getTypeOfMemberTypeReference (
15271532 Type baseObjTy, TypeDecl *typeDecl, ConstraintLocator *locator,
15281533 PreparedOverloadBuilder *preparedOverload) {
1529- assert (!isa<ModuleDecl>(typeDecl) && " Nested module?" );
1534+ ASSERT (!isa<ModuleDecl>(typeDecl) && " Nested module?" );
15301535
15311536 auto memberTy = TypeChecker::substMemberTypeWithBase (typeDecl, baseObjTy);
15321537
@@ -1552,8 +1557,7 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberTypeReference(
15521557 }
15531558
15541559 FunctionType::Param baseObjParam (baseObjTy);
1555- auto openedType = FunctionType::get ({baseObjParam}, memberTy);
1556- return { openedType, openedType, memberTy, memberTy, Type () };
1560+ return FunctionType::get ({baseObjParam}, memberTy);
15571561}
15581562
15591563std::pair<Type, Type> ConstraintSystem::getOpenedStorageType (
@@ -1853,18 +1857,30 @@ static FunctionType *applyOptionality(ValueDecl *value, FunctionType *fnTy) {
18531857
18541858std::tuple<Type, Type, Type>
18551859ConstraintSystem::getTypeOfMemberReferenceImpl (
1856- Type baseTy, ValueDecl *value, DeclContext *useDC, bool isDynamicLookup,
1857- FunctionRefInfo functionRefInfo, ConstraintLocator *locator,
1858- SmallVectorImpl<OpenedType> *replacementsPtr,
1860+ OverloadChoice choice, DeclContext *useDC,
1861+ ConstraintLocator *locator, SmallVectorImpl<OpenedType> *replacementsPtr,
18591862 PreparedOverloadBuilder *preparedOverload) {
1860- ASSERT (!isa<TypeDecl>(value));
18611863 ASSERT (!!preparedOverload == PreparingOverload);
1864+
1865+ auto *value = choice.getDecl ();
1866+ auto functionRefInfo = choice.getFunctionRefInfo ();
1867+
18621868 recordFixIfNeededForPlaceholderInDecl (*this , value, locator);
18631869
18641870 // Figure out the instance type used for the base.
1871+ auto baseTy = choice.getBaseType ();
18651872 Type baseRValueTy = baseTy->getRValueType ();
18661873 auto baseObjTy = baseRValueTy->getMetatypeInstanceType ();
18671874
1875+ Type openedType;
1876+ Type thrownErrorType;
1877+
1878+ if (auto *typeDecl = dyn_cast<TypeDecl>(value)) {
1879+ openedType = getTypeOfMemberTypeReference (baseObjTy, typeDecl,
1880+ locator, preparedOverload);
1881+ return {openedType, thrownErrorType, baseObjTy};
1882+ }
1883+
18681884 // Figure out the declaration context to use when opening this type.
18691885 DeclContext *innerDC = value->getInnermostDeclContext ();
18701886 DeclContext *outerDC = value->getDeclContext ();
@@ -1898,8 +1914,6 @@ ConstraintSystem::getTypeOfMemberReferenceImpl(
18981914 // strip it off later.
18991915 auto hasAppliedSelf = doesMemberRefApplyCurriedSelf (baseRValueTy, value);
19001916
1901- Type openedType;
1902- Type thrownErrorType;
19031917 if (isa<AbstractFunctionDecl>(value) ||
19041918 isa<EnumElementDecl>(value) ||
19051919 isa<MacroDecl>(value)) {
@@ -1987,7 +2001,7 @@ ConstraintSystem::getTypeOfMemberReferenceImpl(
19872001 addConstraint (ConstraintKind::Bind, baseOpenedTy, selfObjTy,
19882002 getConstraintLocator (locator), /* isFavored=*/ false ,
19892003 preparedOverload);
1990- } else if (!isDynamicLookup ) {
2004+ } else if (choice. getKind () != OverloadChoiceKind::DeclViaDynamic ) {
19912005 addSelfConstraint (*this , baseOpenedTy, selfObjTy, locator, preparedOverload);
19922006 }
19932007
@@ -2025,42 +2039,40 @@ ConstraintSystem::getTypeOfMemberReferenceImpl(
20252039}
20262040
20272041DeclReferenceType ConstraintSystem::getTypeOfMemberReference (
2028- Type baseTy, ValueDecl *value, DeclContext *useDC, bool isDynamicLookup,
2029- FunctionRefInfo functionRefInfo, ConstraintLocator *locator,
2042+ OverloadChoice choice, DeclContext *useDC, ConstraintLocator *locator,
20302043 SmallVectorImpl<OpenedType> *replacementsPtr,
20312044 PreparedOverloadBuilder *preparedOverload) {
20322045 ASSERT (!!preparedOverload == PreparingOverload);
20332046
2047+ auto *value = choice.getDecl ();
2048+
20342049 // Figure out the instance type used for the base.
2035- Type baseRValueTy = baseTy ;
2050+ Type baseRValueTy = choice. getBaseType () ;
20362051 Type baseObjTy = baseRValueTy->getMetatypeInstanceType ();
20372052
2038- // If the base is a module type, just use the type of the decl.
2039- if (baseObjTy->getMetatypeInstanceType ()->is <ModuleType>()) {
2040- return getTypeOfReference (value, functionRefInfo, locator, useDC,
2041- preparedOverload);
2042- }
2043-
2044- if (auto *typeDecl = dyn_cast<TypeDecl>(value)) {
2045- return getTypeOfMemberTypeReference (baseObjTy, typeDecl,
2046- locator, preparedOverload);
2047- }
2053+ // A reference to a module member is really unqualified, and should
2054+ // be handled by the caller via getTypeOfReference().
2055+ ASSERT (!baseObjTy->is <ModuleType>());
20482056
20492057 Type openedType, thrownErrorType;
20502058 std::tie (openedType, thrownErrorType, baseObjTy)
2051- = getTypeOfMemberReferenceImpl (baseTy, value, useDC,
2052- isDynamicLookup, functionRefInfo,
2053- locator, replacementsPtr,
2059+ = getTypeOfMemberReferenceImpl (choice, useDC, locator, replacementsPtr,
20542060 preparedOverload);
20552061
2062+ if (isa<TypeDecl>(value)) {
2063+ auto type = openedType->castTo <FunctionType>()->getResult ();
2064+ return { openedType, openedType, type, type, Type () };
2065+ }
2066+
20562067 auto hasAppliedSelf = doesMemberRefApplyCurriedSelf (baseRValueTy, value);
20572068
20582069 // Adjust the opened type for concurrency.
20592070 Type origOpenedType = openedType;
20602071 if (isRequirementOrWitness (locator)) {
20612072 // Don't adjust when doing witness matching, because that can cause cycles.
20622073 } else if (isa<AbstractFunctionDecl>(value) || isa<EnumElementDecl>(value)) {
2063- unsigned numApplies = getNumApplications (hasAppliedSelf, functionRefInfo);
2074+ unsigned numApplies = getNumApplications (
2075+ hasAppliedSelf, choice.getFunctionRefInfo ());
20642076 openedType = adjustFunctionTypeForConcurrency (
20652077 origOpenedType->castTo <FunctionType>(), baseObjTy, value, useDC,
20662078 numApplies, isMainDispatchQueueMember (locator),
@@ -2082,6 +2094,8 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
20822094 origFnType->getParams (), resultTy, origFnType->getExtInfo ());
20832095 }
20842096
2097+ bool isDynamicLookup = (choice.getKind () == OverloadChoiceKind::DeclViaDynamic);
2098+
20852099 // Check if we need to apply a layer of optionality to the type.
20862100 if (!isRequirementOrWitness (locator)) {
20872101 if (isDynamicLookup || value->getAttrs ().hasAttribute <OptionalAttr>()) {
@@ -2833,14 +2847,16 @@ ConstraintSystem::prepareOverloadImpl(ConstraintLocator *locator,
28332847 // Retrieve the type of a reference to the specific declaration choice.
28342848 assert (!baseTy->hasTypeParameter ());
28352849
2850+ // If the base is a module type, it's an unqualified reference.
2851+ if (baseTy->getMetatypeInstanceType ()->is <ModuleType>()) {
2852+ return getTypeOfReference (choice, locator, useDC, preparedOverload);
2853+ }
2854+
28362855 return getTypeOfMemberReference (
2837- baseTy, choice.getDecl (), useDC,
2838- (choice.getKind () == OverloadChoiceKind::DeclViaDynamic),
2839- choice.getFunctionRefInfo (), locator, nullptr , preparedOverload);
2856+ choice, useDC, locator, /* replacements=*/ nullptr , preparedOverload);
28402857 } else {
28412858 return getTypeOfReference (
2842- choice.getDecl (), choice.getFunctionRefInfo (), locator, useDC,
2843- preparedOverload);
2859+ choice, locator, useDC, preparedOverload);
28442860 }
28452861}
28462862
0 commit comments