@@ -1975,8 +1975,13 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
19751975 Type ContextTy = VD->getDeclContext ()->getDeclaredInterfaceType ();
19761976 if (ContextTy) {
19771977 // Look through lvalue types and metatypes
1978- Type MaybeNominalType = (*ExprType)->getRValueType ()
1979- ->getRValueInstanceType ();
1978+ Type MaybeNominalType = (*ExprType)->getRValueType ();
1979+
1980+ if (auto Metatype = MaybeNominalType->getAs <MetatypeType>())
1981+ MaybeNominalType = Metatype->getInstanceType ();
1982+
1983+ if (auto SelfType = MaybeNominalType->getAs <DynamicSelfType>())
1984+ MaybeNominalType = SelfType->getSelfType ();
19801985
19811986 // For optional protocol requirements and dynamic dispatch,
19821987 // strip off optionality from the base type, but only if
@@ -1989,6 +1994,12 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
19891994 if (MaybeNominalType->isAnyObject ())
19901995 return T;
19911996
1997+ // FIXME: Sometimes ExprType is the type of the member here,
1998+ // and not the type of the base. That is inconsistent and
1999+ // should be cleaned up.
2000+ if (!MaybeNominalType->mayHaveMembers ())
2001+ return T;
2002+
19922003 // For everything else, substitute in the base type.
19932004 auto Subs = MaybeNominalType->getMemberSubstitutions (VD);
19942005
@@ -2865,23 +2876,24 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
28652876
28662877 if (auto *NTD = dyn_cast<NominalTypeDecl>(D)) {
28672878 addNominalTypeRef (NTD, Reason);
2868- addConstructorCallsForType (NTD->getInterfaceType (), NTD-> getName (),
2869- Reason);
2879+ addConstructorCallsForType (NTD->getDeclaredInterfaceType (),
2880+ NTD-> getName (), Reason);
28702881 return ;
28712882 }
28722883
28732884 if (auto *TAD = dyn_cast<TypeAliasDecl>(D)) {
28742885 addTypeAliasRef (TAD, Reason);
28752886 auto type = TAD->mapTypeIntoContext (TAD->getUnderlyingTypeLoc ().getType ());
2876- addConstructorCallsForType (type, TAD->getName (), Reason);
2887+ if (type->mayHaveMembers ())
2888+ addConstructorCallsForType (type, TAD->getName (), Reason);
28772889 return ;
28782890 }
28792891
28802892 if (auto *GP = dyn_cast<GenericTypeParamDecl>(D)) {
28812893 addGenericTypeParamRef (GP, Reason);
28822894 for (auto *protocol : GP->getConformingProtocols ())
2883- addConstructorCallsForType (protocol->getInterfaceType (), GP-> getName (),
2884- Reason);
2895+ addConstructorCallsForType (protocol->getDeclaredInterfaceType (),
2896+ GP-> getName (), Reason);
28852897 return ;
28862898 }
28872899
@@ -2934,23 +2946,24 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
29342946
29352947 if (auto *NTD = dyn_cast<NominalTypeDecl>(D)) {
29362948 addNominalTypeRef (NTD, Reason);
2937- addConstructorCallsForType (NTD->getInterfaceType (), NTD-> getName (),
2938- Reason);
2949+ addConstructorCallsForType (NTD->getDeclaredInterfaceType (),
2950+ NTD-> getName (), Reason);
29392951 return ;
29402952 }
29412953
29422954 if (auto *TAD = dyn_cast<TypeAliasDecl>(D)) {
29432955 addTypeAliasRef (TAD, Reason);
29442956 auto type = TAD->mapTypeIntoContext (TAD->getDeclaredInterfaceType ());
2945- addConstructorCallsForType (type, TAD->getName (), Reason);
2957+ if (type->mayHaveMembers ())
2958+ addConstructorCallsForType (type, TAD->getName (), Reason);
29462959 return ;
29472960 }
29482961
29492962 if (auto *GP = dyn_cast<GenericTypeParamDecl>(D)) {
29502963 addGenericTypeParamRef (GP, Reason);
29512964 for (auto *protocol : GP->getConformingProtocols ())
2952- addConstructorCallsForType (protocol->getInterfaceType (), GP-> getName (),
2953- Reason);
2965+ addConstructorCallsForType (protocol->getDeclaredInterfaceType (),
2966+ GP-> getName (), Reason);
29542967 return ;
29552968 }
29562969
0 commit comments