@@ -999,8 +999,6 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
999
999
1000
1000
// Look in the generic parameters after checking our local declaration.
1001
1001
GenericParams = AFD->getGenericParams ();
1002
- } else if (auto *SD = dyn_cast<SubscriptDecl>(DC)) {
1003
- GenericParams = SD->getGenericParams ();
1004
1002
} else if (auto *ACE = dyn_cast<AbstractClosureExpr>(DC)) {
1005
1003
// Look for local variables; normally, the parser resolves these
1006
1004
// for us, but it can't do the right thing inside local types.
@@ -1042,12 +1040,14 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
1042
1040
continue ;
1043
1041
} else {
1044
1042
assert (isa<TopLevelCodeDecl>(DC) || isa<Initializer>(DC) ||
1045
- isa<TypeAliasDecl>(DC));
1043
+ isa<TypeAliasDecl>(DC) || isa<SubscriptDecl>(DC) );
1046
1044
if (!isCascadingUse.hasValue ())
1047
1045
isCascadingUse = DC->isCascadingContextForLookup (false );
1048
1046
}
1049
1047
1050
- // Check the generic parameters for something with the given name.
1048
+ // If we're inside a function context, we've already moved to
1049
+ // the parent DC, so we have to check the function's generic
1050
+ // parameters first.
1051
1051
if (GenericParams) {
1052
1052
namelookup::FindLocalVal localVal (SM, Loc, Consumer);
1053
1053
localVal.checkGenericParams (GenericParams);
@@ -1056,6 +1056,30 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
1056
1056
return ;
1057
1057
}
1058
1058
1059
+ // Check the generic parameters of our context.
1060
+ GenericParamList *dcGenericParams = nullptr ;
1061
+ if (auto nominal = dyn_cast<NominalTypeDecl>(DC))
1062
+ dcGenericParams = nominal->getGenericParams ();
1063
+ else if (auto ext = dyn_cast<ExtensionDecl>(DC))
1064
+ dcGenericParams = ext->getGenericParams ();
1065
+ else if (auto subscript = dyn_cast<SubscriptDecl>(DC))
1066
+ dcGenericParams = subscript->getGenericParams ();
1067
+
1068
+ while (dcGenericParams) {
1069
+ namelookup::FindLocalVal localVal (SM, Loc, Consumer);
1070
+ localVal.checkGenericParams (dcGenericParams);
1071
+
1072
+ if (shouldReturnBasedOnResults ())
1073
+ return ;
1074
+
1075
+ // Extensions of nested types have multiple levels of
1076
+ // generic parameters, so we have to visit them explicitly.
1077
+ if (!isa<ExtensionDecl>(DC))
1078
+ break ;
1079
+
1080
+ dcGenericParams = dcGenericParams->getOuterParameters ();
1081
+ }
1082
+
1059
1083
if (BaseDC && !lookupDecls.empty ()) {
1060
1084
NLOptions options = baseNLOptions;
1061
1085
if (isCascadingUse.getValue ())
@@ -1071,12 +1095,9 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
1071
1095
// Classify this declaration.
1072
1096
FoundAny = true ;
1073
1097
1074
- // Types are local or metatype members .
1098
+ // Types are formally members of the metatype .
1075
1099
if (auto TD = dyn_cast<TypeDecl>(Result)) {
1076
- if (isa<GenericTypeParamDecl>(TD))
1077
- Results.push_back (LookupResultEntry (Result));
1078
- else
1079
- Results.push_back (LookupResultEntry (MetaBaseDC, Result));
1100
+ Results.push_back (LookupResultEntry (MetaBaseDC, Result));
1080
1101
continue ;
1081
1102
}
1082
1103
@@ -1108,29 +1129,6 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
1108
1129
}
1109
1130
}
1110
1131
1111
- // Check the generic parameters if our context is a generic type or
1112
- // extension thereof.
1113
- GenericParamList *dcGenericParams = nullptr ;
1114
- if (auto nominal = dyn_cast<NominalTypeDecl>(DC))
1115
- dcGenericParams = nominal->getGenericParams ();
1116
- else if (auto ext = dyn_cast<ExtensionDecl>(DC))
1117
- dcGenericParams = ext->getGenericParams ();
1118
- else if (auto subscript = dyn_cast<SubscriptDecl>(DC))
1119
- dcGenericParams = subscript->getGenericParams ();
1120
-
1121
- while (dcGenericParams) {
1122
- namelookup::FindLocalVal localVal (SM, Loc, Consumer);
1123
- localVal.checkGenericParams (dcGenericParams);
1124
-
1125
- if (shouldReturnBasedOnResults ())
1126
- return ;
1127
-
1128
- if (!isa<ExtensionDecl>(DC))
1129
- break ;
1130
-
1131
- dcGenericParams = dcGenericParams->getOuterParameters ();
1132
- }
1133
-
1134
1132
DC = DC->getParentForLookup ();
1135
1133
}
1136
1134
0 commit comments