You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The SymbolResolver resolves local variables in the same scope even if the first assignment to this variable occurs after a usage. E.g. in python, this leads to an UnboundLocalError.
defcomprehension_with_list_assignment_and_index_variable_reversed():
b= [0, 1, 2]
a=1
[afor (b[a], a) in [('this', 0), ('is', 1), ('fun', 2)]] # This crashes because the "a" in the tuple shadows the outer variable and "UnboundLocalError: cannot access local variable 'a' where it is not associated with a value".print(b) # prints nothing due to crash
Note: This is not to be confused with a variable which has not been declared (yet) within the scope/context.
I would say that `refersTo` should be null. I think we did that in other cases where we have an unbound error as well
We should identify further cases which can cause such behavior and add respective test cases (I didn't find anything suitable in the python language module on a first glance)
The
SymbolResolver
resolves local variables in the same scope even if the first assignment to this variable occurs after a usage. E.g. in python, this leads to anUnboundLocalError
.Example code causing this issue which is currently not implemented accordingly in the CPG (see https://github.com/Fraunhofer-AISEC/cpg/blob/ak/python-comprehension-scope/cpg-language-python/src/test/resources/python/comprehension.py#L70 and for the test see https://github.com/Fraunhofer-AISEC/cpg/blob/ak/python-comprehension-scope/cpg-language-python/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/python/CollectionComprehensionTest.kt#L1385):
Note: This is not to be confused with a variable which has not been declared (yet) within the scope/context.
Originally posted by @oxisto in #2019 (comment)
The text was updated successfully, but these errors were encountered: