brownplt / pyret-lang

The Pyret language.
Other
1.07k stars 111 forks source link

reserved `return` is not uniformly blocked #1669

Closed shriram closed 6 months ago

shriram commented 2 years ago

In the following program, this definition

data LoopStatus:
  | return(final-value)
  | next-2(new-arg-1, new-arg-2)
end

and this use

fun loop-2(f, arg-1, arg-2):
  r = f(arg-1, arg-2)
  cases (LoopStatus) r:
    | return(v) => v
    | next-2(new-arg-1, new-arg-2) => loop-2(f, new-arg-1, new-arg-2)
  end
end

are accepted without complaint, but this program

fun gcd(p, q):
  for loop-2(a from p, b from q):
    if b == 0:
      return(a)
    else:
      next-2(b, num-modulo(a, b))
    end
  end
end

produces a "name is reserved" error for return. I feel like the data definition itself should not have been permitted, since at least straightforward ways of using it are not permitted.

blerner commented 6 months ago

Good catch; this seems like an easy fix. @jpolitz just double-check the commit above that it looks plausible; the tests should all succeed.