@@ -1105,16 +1105,25 @@ WitnessChecker::WitnessChecker(ASTContext &ctx, ProtocolDecl *proto,
1105
1105
void
1106
1106
WitnessChecker::lookupValueWitnessesViaImplementsAttr (
1107
1107
ValueDecl *req, SmallVector<ValueDecl *, 4 > &witnesses) {
1108
- auto lookupOptions = defaultMemberTypeLookupOptions;
1109
- lookupOptions -= NameLookupFlags::PerformConformanceCheck;
1110
- lookupOptions |= NameLookupFlags::IncludeAttributeImplements;
1111
- auto candidates = TypeChecker::lookupMember (DC, Adoptee, req->createNameRef (),
1112
- lookupOptions);
1113
- for (auto candidate : candidates) {
1114
- if (witnessHasImplementsAttrForExactRequirement (candidate.getValueDecl (), req)) {
1115
- witnesses.push_back (candidate.getValueDecl ());
1116
- }
1108
+
1109
+ auto name = req->createNameRef ();
1110
+ auto *nominal = Adoptee->getAnyNominal ();
1111
+
1112
+ NLOptions subOptions = (NL_ProtocolMembers | NL_IncludeAttributeImplements);
1113
+
1114
+ nominal->synthesizeSemanticMembersIfNeeded (name.getFullName ());
1115
+
1116
+ SmallVector<ValueDecl *, 4 > lookupResults;
1117
+ DC->lookupQualified (nominal, name, subOptions, lookupResults);
1118
+
1119
+ for (auto decl : lookupResults) {
1120
+ if (!isa<ProtocolDecl>(decl->getDeclContext ()))
1121
+ if (witnessHasImplementsAttrForExactRequirement (decl, req))
1122
+ witnesses.push_back (decl);
1117
1123
}
1124
+
1125
+ removeOverriddenDecls (witnesses);
1126
+ removeShadowedDecls (witnesses, DC);
1118
1127
}
1119
1128
1120
1129
SmallVector<ValueDecl *, 4 >
@@ -1147,23 +1156,34 @@ WitnessChecker::lookupValueWitnesses(ValueDecl *req, bool *ignoringNames) {
1147
1156
}
1148
1157
} else {
1149
1158
// Variable/function/subscript requirements.
1150
- auto lookupOptions = defaultMemberTypeLookupOptions;
1151
- lookupOptions -= NameLookupFlags::PerformConformanceCheck;
1152
-
1153
- auto candidates = TypeChecker::lookupMember (DC, Adoptee, reqName,
1154
- lookupOptions);
1159
+ auto *nominal = Adoptee->getAnyNominal ();
1160
+ nominal->synthesizeSemanticMembersIfNeeded (reqName.getFullName ());
1161
+
1162
+ SmallVector<ValueDecl *, 4 > lookupResults;
1163
+ bool addedAny = false ;
1164
+ DC->lookupQualified (nominal, reqName, NL_ProtocolMembers, lookupResults);
1165
+ for (auto *decl : lookupResults) {
1166
+ if (!isa<ProtocolDecl>(decl->getDeclContext ())) {
1167
+ witnesses.push_back (decl);
1168
+ addedAny = true ;
1169
+ }
1170
+ };
1155
1171
1156
1172
// If we didn't find anything with the appropriate name, look
1157
1173
// again using only the base name.
1158
- if (candidates.empty () && ignoringNames) {
1159
- candidates = TypeChecker::lookupMember (DC, Adoptee, reqBaseName,
1160
- lookupOptions);
1174
+ if (!addedAny && ignoringNames) {
1175
+ lookupResults.clear ();
1176
+ DC->lookupQualified (nominal, reqBaseName, NL_ProtocolMembers, lookupResults);
1177
+ for (auto *decl : lookupResults) {
1178
+ if (!isa<ProtocolDecl>(decl->getDeclContext ()))
1179
+ witnesses.push_back (decl);
1180
+ }
1181
+
1161
1182
*ignoringNames = true ;
1162
1183
}
1163
1184
1164
- for (auto candidate : candidates) {
1165
- witnesses.push_back (candidate.getValueDecl ());
1166
- }
1185
+ removeOverriddenDecls (witnesses);
1186
+ removeShadowedDecls (witnesses, DC);
1167
1187
}
1168
1188
1169
1189
return witnesses;
@@ -5121,16 +5141,20 @@ diagnoseMissingAppendInterpolationMethod(NominalTypeDecl *typeDecl) {
5121
5141
5122
5142
static bool hasValidMethod (NominalTypeDecl *typeDecl,
5123
5143
SmallVectorImpl<InvalidMethod> &invalid) {
5124
- auto type = typeDecl->getDeclaredType ();
5144
+ NLOptions subOptions = NL_QualifiedDefault;
5145
+ subOptions |= NL_ProtocolMembers;
5146
+
5125
5147
DeclNameRef baseName (typeDecl->getASTContext ().Id_appendInterpolation );
5126
- auto lookupOptions = defaultMemberTypeLookupOptions;
5127
- lookupOptions -= NameLookupFlags::PerformConformanceCheck;
5128
5148
5129
- for (auto resultEntry :
5130
- TypeChecker::lookupMember (typeDecl, type, baseName, lookupOptions)) {
5131
- auto method = dyn_cast<FuncDecl>(resultEntry.getValueDecl ());
5149
+ SmallVector<ValueDecl *, 4 > lookupResults;
5150
+ typeDecl->lookupQualified (typeDecl, baseName, subOptions, lookupResults);
5151
+ for (auto decl : lookupResults) {
5152
+ auto method = dyn_cast<FuncDecl>(decl);
5132
5153
if (!method) continue ;
5133
-
5154
+
5155
+ if (isa<ProtocolDecl>(method->getDeclContext ()))
5156
+ continue ;
5157
+
5134
5158
if (method->isStatic ()) {
5135
5159
invalid.emplace_back (method, Reason::Static);
5136
5160
continue ;
0 commit comments