File tree Expand file tree Collapse file tree 4 files changed +17
-2
lines changed
experimental/dataflow/typetracking
library-tests/variables/definitions Expand file tree Collapse file tree 4 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -640,12 +640,23 @@ class DefinitionNode extends ControlFlowNode {
640
640
exists ( Assign a | list_or_tuple_nested_element ( a .getATarget ( ) ) .getAFlowNode ( ) = this )
641
641
or
642
642
exists ( For for | for .getTarget ( ) .getAFlowNode ( ) = this )
643
+ or
644
+ exists ( Parameter param | this = param .asName ( ) .getAFlowNode ( ) and exists ( param .getDefault ( ) ) )
643
645
}
644
646
645
647
/** flow node corresponding to the value assigned for the definition corresponding to this flow node */
646
648
ControlFlowNode getValue ( ) {
647
649
result = assigned_value ( this .getNode ( ) ) .getAFlowNode ( ) and
648
- ( result .getBasicBlock ( ) .dominates ( this .getBasicBlock ( ) ) or result .isImport ( ) )
650
+ (
651
+ result .getBasicBlock ( ) .dominates ( this .getBasicBlock ( ) )
652
+ or
653
+ result .isImport ( )
654
+ or
655
+ // since the default value for a parameter is evaluated in the same basic block as
656
+ // the function definition, but the parameter belongs to the basic block of the function,
657
+ // there is no dominance relationship between the two.
658
+ exists ( Parameter param | this = param .asName ( ) .getAFlowNode ( ) )
659
+ )
649
660
}
650
661
}
651
662
@@ -795,6 +806,8 @@ private AstNode assigned_value(Expr lhs) {
795
806
or
796
807
/* for lhs in seq: => `result` is the `for` node, representing the `iter(next(seq))` operation. */
797
808
result .( For ) .getTarget ( ) = lhs
809
+ or
810
+ exists ( Parameter param | lhs = param .asName ( ) and result = param .getDefault ( ) )
798
811
}
799
812
800
813
predicate nested_sequence_assign (
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ def from_parameter_default():
71
71
def outer (x = tracked ): # $tracked
72
72
print (x ) # $tracked
73
73
def inner ():
74
- print (x ) # $ MISSING: tracked
74
+ print (x ) # $ tracked
75
75
print (x_alias ) # $tracked
76
76
return x # $tracked
77
77
also_x = outer () # $tracked
Original file line number Diff line number Diff line change 1
1
| test.py:3:5:3:9 | ControlFlowNode for fail5 | test.py:3:1:3:13 | ControlFlowNode for FunctionExpr |
2
2
| test.py:4:5:4:8 | ControlFlowNode for Tuple | test.py:4:12:4:12 | ControlFlowNode for t |
3
3
| test.py:7:5:7:26 | ControlFlowNode for default_value_in_param | test.py:7:1:7:33 | ControlFlowNode for FunctionExpr |
4
+ | test.py:7:28:7:28 | ControlFlowNode for x | test.py:7:30:7:31 | ControlFlowNode for IntegerLiteral |
Original file line number Diff line number Diff line change 3
3
| 4 | 5 | ControlFlowNode for x |
4
4
| 4 | 8 | ControlFlowNode for y |
5
5
| 7 | 5 | ControlFlowNode for default_value_in_param |
6
+ | 7 | 28 | ControlFlowNode for x |
You can’t perform that action at this time.
0 commit comments