-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Odd behaviour with shadowing variables #840
Comments
Note that we're following Python's scoping semantics. For example the following code would be fine @guppy
def foo() -> int:
while True:
j = 1
if condition():
break
# Use of j outside loop is legal since the compiler can
# prove that it is definitely assigned
return j So the
This feels a bit dangerous as it might confuse users: j = 0
@guppy
def foo() -> int:
j = 1
return py(j) # Making this evaluate to 0 seems counter intuitive to me I'd prefer to force users to be explicit and give them an error pointing to the fact that they're using a Guppy variable:
But the error you're getting in your example is clearly worse! We should be outputting the same message as above. The problem is that given a decorated function |
I actually don't find this counter intuitive, since my mind reads |
Running the above results in error:
If I change the name of
j
to anything else, the code runs fine. This seems a little odd / buggy since the localj
is out of scope by the time the compile time one is called.It seems to me that it should be possible to use
py(j)
even when the localj
is in scope, because thepy(...)
function should be enough for the compiler to differentiate between the two?The text was updated successfully, but these errors were encountered: