File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed
python/ql/test/query-tests/Statements/unreachable_nonlocal Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ Statements/UnreachableCode.ql
Original file line number Diff line number Diff line change 1+
2+ def nonlocal_fp ():
3+ test = False
4+ def set_test ():
5+ nonlocal test
6+ test = True
7+ set_test ()
8+ if test :
9+ raise Exception ("Foo" )
10+
11+
12+ # A couple of false negatives, roughly in order of complexity
13+
14+ # test is nonlocal, but not mutated
15+ def nonlocal_fn1 ():
16+ test = False
17+ def set_test ():
18+ nonlocal test
19+ set_test ()
20+ if test :
21+ raise Exception ("Foo" )
22+
23+ # test is nonlocal and mutated, but does not change truthiness
24+ def nonlocal_fn2 ():
25+ test = False
26+ def set_test ():
27+ nonlocal test
28+ test = 0
29+ set_test ()
30+ if test :
31+ raise Exception ("Foo" )
32+
33+ # test is nonlocal and changes truthiness, but the function is never called
34+ def nonlocal_fn3 ():
35+ test = False
36+ def set_test ():
37+ nonlocal test
38+ test = True
39+ if test :
40+ raise Exception ("Foo" )
41+
42+ # test is nonlocal and changes truthiness, but only if the given argument is true
43+ def nonlocal_fn4 (x ):
44+ test = False
45+ def set_test ():
46+ nonlocal test
47+ test = True
48+ if x :
49+ set_test ()
50+ if test :
51+ raise Exception ("Foo" )
You can’t perform that action at this time.
0 commit comments