SMAT-Lab / Scalpel

Scalpel: The Python Static Analysis Framework
Apache License 2.0
278 stars 42 forks source link

Duplicate entry (parameter and variable) for function parameter during type inferencing #35

Closed khatchad closed 2 years ago

khatchad commented 2 years ago

Consider the following modified type_infer_example.py (`:

from os import getcwd

def my_function(x):
    x = "Current working directory: "
    return x + getcwd()

Running type_infer_tutorial.py on this file, I get the following output (slightly modified for clarify):

python type_infer_tutorial.py
{'file': 'type_infer_example.py', 'line_number': 4, 'function': 'my_function', 'type': {'str'}}
{'file': 'type_infer_example.py', 'line_number': 4, 'parameter': 'x', 'function': 'my_function', 'type': {'any'}}
{'file': 'type_infer_example.py', 'line_number': 5, 'variable': 'x', 'function': 'my_function', 'type': {'str'}}

Above, there are two entries for x but, actually, there is only one x, i.e., the parameter x. In other words, there is no variable x.

billquan commented 2 years ago

Hi, In this example code, I believe that x is reassigned to the string "Current working directory:". As such, there is a local variable x which is a str and we could not infer the parameter type from the given information so parameter 'x' would be any. Hope that helps.

khatchad commented 2 years ago

Ah, I see, the type inferencing is per line, i.e., there is a variable x at some line and at this line it has some type. Thanks.