mirror of
https://github.com/github/codeql.git
synced 2026-04-25 16:55:19 +02:00
Python: Handle loop constructs outside of loops
Observed on some test files in Nuitka/Nuitka, having `break` and `continue` outside of loops in Python is (to Python) a syntax error, but our parser happily accepted this broken syntax. This then caused issues further downstream in the control-flow construction, as it broke some invariants. To fix this we now skip the code that would previously fail when the invariants are broken. Co-authored-by: yoff <yoff@github.com>
This commit is contained in:
10
python/ql/test/extractor-tests/syntax_error/without_loop.py
Normal file
10
python/ql/test/extractor-tests/syntax_error/without_loop.py
Normal file
@@ -0,0 +1,10 @@
|
||||
# The following constructs are syntax errors in Python, as they are not inside a loop.
|
||||
# However, our parser does not consider this code to be syntactically incorrect.
|
||||
# Thus, this test is really observing that allowing these constructs does not break any other parts
|
||||
# of the extractor.
|
||||
|
||||
if True:
|
||||
break
|
||||
|
||||
if True:
|
||||
continue
|
||||
Reference in New Issue
Block a user