@@ -2942,40 +2942,6 @@ getArgumentLabels(ConstraintSystem &cs, ConstraintLocatorBuilder locator) {
2942
2942
return known->second ;
2943
2943
}
2944
2944
2945
- // / Returns the function declaration corresponding to a @dynamicCallable
2946
- // / attribute required method (if it exists) implemented by a type. Otherwise,
2947
- // / return nullptr.
2948
- static FuncDecl *
2949
- lookupDynamicCallableMethod (Type type, ConstraintSystem &CS,
2950
- const ConstraintLocatorBuilder &locator,
2951
- StringRef methodName, StringRef argumentName,
2952
- bool hasKeywordArgs, bool &error) {
2953
- auto &ctx = CS.getASTContext ();
2954
- auto decl = type->getAnyNominal ();
2955
- auto option = DeclName (ctx, DeclBaseName (ctx.getIdentifier (methodName)),
2956
- { ctx.getIdentifier (argumentName) });
2957
- auto matches = CS.performMemberLookup (ConstraintKind::ValueMember,
2958
- option, type,
2959
- FunctionRefKind::SingleApply,
2960
- CS.getConstraintLocator (locator),
2961
- /* includeInaccessibleMembers*/ false );
2962
- // Filter valid candidates.
2963
- auto candidates = matches.ViableCandidates ;
2964
- auto filter = [&](OverloadChoice choice) {
2965
- auto cand = cast<FuncDecl>(choice.getDecl ());
2966
- return !isValidDynamicCallableMethod (cand, decl, CS.TC , hasKeywordArgs);
2967
- };
2968
- candidates.erase (std::remove_if (candidates.begin (), candidates.end (), filter),
2969
- candidates.end ());
2970
-
2971
- // If there is one candidate, return it. Otherwise, return nullptr.
2972
- auto size = candidates.size ();
2973
- if (size == 1 ) return cast<FuncDecl>(candidates.front ().getDecl ());
2974
- // If there are >1 candidates, it is an overload error.
2975
- else if (size > 1 ) error = true ;
2976
- return nullptr ;
2977
- }
2978
-
2979
2945
// / Return true if the specified type or a super-class/super-protocol has the
2980
2946
// / @dynamicMemberLookup attribute on it. This implementation is not
2981
2947
// / particularly fast in the face of deep class hierarchies or lots of protocol
@@ -4287,22 +4253,54 @@ ConstraintSystem::simplifyKeyPathApplicationConstraint(
4287
4253
return unsolved ();
4288
4254
}
4289
4255
4256
+ // / Returns the function declaration corresponding to a @dynamicCallable
4257
+ // / attribute required method (if it exists) implemented by a type. Otherwise,
4258
+ // / return nullptr.
4259
+ static FuncDecl *
4260
+ lookupDynamicCallableMethod (Type type, ConstraintSystem &CS,
4261
+ const ConstraintLocatorBuilder &locator,
4262
+ Identifier argumentName, bool hasKeywordArgs,
4263
+ bool &error) {
4264
+ auto &ctx = CS.getASTContext ();
4265
+ auto decl = type->getAnyNominal ();
4266
+ auto methodName = DeclName (ctx, ctx.Id_dynamicallyCall , { argumentName });
4267
+ auto matches = CS.performMemberLookup (ConstraintKind::ValueMember,
4268
+ methodName, type,
4269
+ FunctionRefKind::SingleApply,
4270
+ CS.getConstraintLocator (locator),
4271
+ /* includeInaccessibleMembers*/ false );
4272
+ // Filter valid candidates.
4273
+ auto candidates = matches.ViableCandidates ;
4274
+ auto filter = [&](OverloadChoice choice) {
4275
+ auto cand = cast<FuncDecl>(choice.getDecl ());
4276
+ return !isValidDynamicCallableMethod (cand, decl, CS.TC , hasKeywordArgs);
4277
+ };
4278
+ candidates.erase (std::remove_if (candidates.begin (), candidates.end (), filter),
4279
+ candidates.end ());
4280
+
4281
+ // If there is one candidate, return it. Otherwise, return nullptr.
4282
+ auto size = candidates.size ();
4283
+ if (size == 1 ) return cast<FuncDecl>(candidates.front ().getDecl ());
4284
+ // If there are >1 candidates, it is an overload error.
4285
+ else if (size > 1 ) error = true ;
4286
+ return nullptr ;
4287
+ }
4288
+
4290
4289
// / Looks up and returns the @dynamicCallable required methods (if they exist)
4291
4290
// / implemented by a type. This function should not be called directly: instead,
4292
4291
// / call `getDynamicCallableMethods` which performs caching.
4293
4292
static DynamicCallableMethods
4294
4293
lookupDynamicCallableMethods (Type type, ConstraintSystem &CS,
4295
4294
const ConstraintLocatorBuilder &locator,
4296
4295
bool &error) {
4296
+ auto &ctx = CS.getASTContext ();
4297
4297
DynamicCallableMethods methods;
4298
4298
methods.argumentsMethod =
4299
- lookupDynamicCallableMethod (type, CS, locator, " dynamicallyCall" ,
4300
- " withArguments" , /* hasKeywordArgs*/ false ,
4301
- error);
4299
+ lookupDynamicCallableMethod (type, CS, locator, ctx.Id_withArguments ,
4300
+ /* hasKeywordArgs*/ false , error);
4302
4301
methods.keywordArgumentsMethod =
4303
- lookupDynamicCallableMethod (type, CS, locator, " dynamicallyCall" ,
4304
- " withKeywordArguments" , /* hasKeywordArgs*/ true ,
4305
- error);
4302
+ lookupDynamicCallableMethod (type, CS, locator, ctx.Id_withKeywordArguments ,
4303
+ /* hasKeywordArgs*/ true , error);
4306
4304
return methods;
4307
4305
}
4308
4306
0 commit comments