pyret-lang icon indicating copy to clipboard operation
pyret-lang copied to clipboard

`block` in `where` leaks declared names into global scope

Open molenzwiebel opened this issue 4 years ago • 1 comments

Simple example:

fun one():
  1
where:
  block:
    a = 1
    one() is 1
  end
end

# Uncommenting this will yield the following error: "The identifier a is unbound"
# print(a) 

a = 2 # "The declaration of a shadows a previous declaration of a"

For some reason, Pyret thinks that the second a declaration shadows the first. However, we aren't able to reference that first one in the global scope (as expected). Unsure whether this is an issue with where or specifically block inside where.

molenzwiebel avatar Jun 28 '21 10:06 molenzwiebel

This is roughly a duplicate of https://github.com/brownplt/pyret-lang/issues/1544. The issue is that testing blocks are moved to the end of the program, so it's actually the top a that is shadowing the outer a. The discussion at #1544 is basically laying out the same confusions as this; I'll leave this open because it seems confusion enough to do something about.

Thanks!

jpolitz avatar Jun 30 '21 16:06 jpolitz