@@ -71,24 +71,20 @@ private string getArgLabelsFromCall(CallExpr call) {
7171 )
7272}
7373
74- pragma [ nomagic]
75- private predicate methodCallSelector ( CallExpr call , string name , string argLabels ) {
76- name = getSimpleNameFromExpr ( call .getCallee ( ) ) and
77- argLabels = getArgLabelsFromCall ( call )
78- }
79-
8074/**
81- * Holds if `call` invokes a setter that models refer to as `name`. By convention, the setter
82- * method invoked by a call to `foo` is named `foo:set` in models, such as `subscript:set` for
83- * `x[i] = y`.
75+ * Holds if `call` is a method call with the given `name` and `argLabels`.
8476 *
85- * The new value is passed as an extra named argument `#newValue` after the explicit ones, so
86- * models refer to it as `Argument[#newValue:]`, e.g. `subscript:set (_:#newValue:)`.
77+ * A call to a setter method, such as `x[i]` in `x[i] = y`, passes the new value as an extra
78+ * argument named `#newValue`, so models refer to it as e.g. `subscript(_:#newValue:)`.
8779 */
8880pragma [ nomagic]
89- private predicate setterCallSelector ( CallExpr call , string name , string argLabels ) {
90- name = call .getCallee ( ) .( MemberAccessExpr ) .getMemberName ( ) + ":set" and
91- argLabels = getArgLabelsFromCall ( call ) + "#newValue:"
81+ private predicate methodCallSelector ( DataFlowCall call , string name , string argLabels ) {
82+ exists ( CallExpr e | e = call .getCallExpr ( ) |
83+ name = getSimpleNameFromExpr ( e .getCallee ( ) ) and
84+ if e = call .asSetterCall ( )
85+ then argLabels = getArgLabelsFromCall ( e ) + "#newValue:"
86+ else argLabels = getArgLabelsFromCall ( e )
87+ )
9288}
9389
9490pragma [ nomagic]
@@ -126,13 +122,10 @@ private string getArgLabelsFromCallable(Callable callable) {
126122}
127123
128124pragma [ nomagic]
129- private predicate callableSelector ( Callable callable , string type , string name , string argLabels ) {
130- (
131- name = callable .( FunctionDeclaration ) .getName ( ) and
132- not callable instanceof SetterMethodDeclaration
133- or
134- name = callable .( SetterMethodDeclaration ) .getName ( ) + ":set"
135- ) and
125+ private predicate callableSelector (
126+ FunctionDeclaration callable , string type , string name , string argLabels
127+ ) {
128+ name = callable .getName ( ) and
136129 argLabels = getArgLabelsFromCallable ( callable ) and
137130 exists ( ClassLikeDeclaration cls |
138131 callable = cls .getAMemberIncludingExtensions ( ) and
@@ -230,10 +223,7 @@ class Selector extends TSelector {
230223 predicate matchesCall ( DataFlowCall call ) {
231224 exists ( string name , string argLabels |
232225 this .matchesMethodCallSelector ( name , argLabels ) and
233- methodCallSelector ( call .asExplicitCall ( ) , name , argLabels )
234- or
235- this .matchesMethodCallSelector ( name , argLabels ) and
236- setterCallSelector ( call .asSetterCall ( ) , name , argLabels )
226+ methodCallSelector ( call , name , argLabels )
237227 or
238228 this .matchesConstructorCallSelector ( name , argLabels ) and
239229 constructorCallSelector ( call .asExplicitCall ( ) , name , argLabels )
@@ -370,8 +360,7 @@ private DataFlow::Node getSinkFromCall(DataFlowCall call, AccessPathToken token)
370360 // The new value passed to a setter method, as the named argument `#newValue`
371361 token .getName ( ) = "Argument" and
372362 token .getAnArgument ( ) = "#newValue:" and
373- result .( BuilderNode ) .isSetterValueArgument ( call ) and
374- call .asSetterCall ( ) instanceof CallExpr
363+ result .( BuilderNode ) .isSetterValueArgument ( call )
375364 or
376365 token .getName ( ) = "Argument" and
377366 token .getAnArgument ( ) = "self" and
0 commit comments