differentmatt / filbert

JavaScript parser of Python
Other
133 stars 27 forks source link

Don't allow calling functions not defined yet #55

Open differentmatt opened 9 years ago

differentmatt commented 9 years ago

This can break in a weird way for some scenarios (null param) currently, because createParamsObj is not applied to user functions that haven't been defined yet: https://github.com/differentmatt/filbert/blob/master/filbert.js#L2178

But, this isn't valid Python, so the fix is not to make the scope.isUserFunction() call more comprehensive. Instead, we need to throw a nice Python-like error as show below. This would probably be a runtime check of some sort.

print(foo()) # foo not defined yet
def foo():
  return 5
10:19:02:/tmp$ python test.py 
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    print(foo())
NameError: name 'foo' is not defined

Related issue: https://github.com/codecombat/codecombat/issues/2073