@@ -279,12 +279,16 @@ module ArgumentPassing {
279279
280280 /**
281281 * Gets the argument to `call` that is passed to the `n`th parameter of `callable`.
282+ * If it is a positional argument, it must appear at position `argNr`.
283+ * `argNr` will differ from `n` for method- or class calls, where the first parameter
284+ * is `self` and the first positional arguemnt is passed to the second positional parameter.
282285 */
283- Node getArg ( CallNode call , CallableValue callable , int n ) {
286+ Node getArg ( CallNode call , int argNr , CallableValue callable , int n ) {
284287 connects ( call , callable ) and
288+ n - argNr in [ 0 , 1 ] and // constrain for now to limit the size of the predicate; we only use it to insert one argument (self).
285289 (
286290 // positional argument
287- result = TCfgNode ( call .getArg ( n ) )
291+ result = TCfgNode ( call .getArg ( argNr ) )
288292 or
289293 // keyword argument
290294 exists ( Function f , string argName |
@@ -305,7 +309,7 @@ module ArgumentPassing {
305309 or
306310 // argument unpacked from dict
307311 exists ( string name |
308- call_unpacks ( call , callable , name , n ) and
312+ call_unpacks ( call , argNr , callable , name , n ) and
309313 result = TKwUnpacked ( call , callable , name )
310314 )
311315 )
@@ -339,11 +343,12 @@ module ArgumentPassing {
339343 * Holds if `call` unpacks a dictionary argument in order to pass it via `name`.
340344 * It will then be passed to the `n`th parameter of `callable`.
341345 */
342- predicate call_unpacks ( CallNode call , CallableValue callable , string name , int n ) {
346+ predicate call_unpacks ( CallNode call , int argNr , CallableValue callable , string name , int n ) {
343347 connects ( call , callable ) and
348+ n - argNr in [ 0 , 1 ] and
344349 exists ( Function f |
345350 f = callable .getScope ( ) and
346- not exists ( call .getArg ( n ) ) and // no positional arguement available
351+ not exists ( call .getArg ( argNr ) ) and // no positional arguement available
347352 name = f .getArgName ( n ) and
348353 // not exists(call.getArgByName(name)) and // only matches keyword arguments not preceded by **
349354 not call .getNode ( ) .getANamedArg ( ) .( Keyword ) .getArg ( ) = name and // no keyword argument available
@@ -478,7 +483,7 @@ class CallNodeCall extends DataFlowCall, TCallNode {
478483
479484 override string toString ( ) { result = call .toString ( ) }
480485
481- override Node getArg ( int n ) { result = getArg ( call , callable .getCallableValue ( ) , n ) }
486+ override Node getArg ( int n ) { result = getArg ( call , n , callable .getCallableValue ( ) , n ) }
482487
483488 override ControlFlowNode getNode ( ) { result = call }
484489
@@ -502,7 +507,7 @@ class ClassCall extends DataFlowCall, TClassCall {
502507 override string toString ( ) { result = call .toString ( ) }
503508
504509 override Node getArg ( int n ) {
505- n > 0 and result = getArg ( call , this .getCallableValue ( ) , n - 1 )
510+ n > 0 and result = getArg ( call , n - 1 , this .getCallableValue ( ) , n )
506511 or
507512 n = 0 and result = TSyntheticPreUpdateNode ( TCfgNode ( call ) )
508513 }
@@ -918,7 +923,7 @@ predicate kwUnpackReadStep(CfgNode nodeFrom, DictionaryElementContent c, Node no
918923cached
919924predicate clearsContent ( Node n , Content c ) {
920925 exists ( CallNode call , CallableValue callable , string name |
921- call_unpacks ( call , callable , name , _) and
926+ call_unpacks ( call , _ , callable , name , _) and
922927 n = TKwOverflowNode ( call , callable ) and
923928 c .( DictionaryElementContent ) .getKey ( ) = name
924929 )
0 commit comments