-
Notifications
You must be signed in to change notification settings - Fork 63
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
Add flag to raise SyntaxErrors in eval
at runtime
#2310
Comments
https://github.com/natalie-lang/natalie/blob/master/lib/natalie/compiler/pass1.rb#L2361-L2380 We do something similar with regexp: parse it at compile time, and generate instructions to raise an exception if it cannot be parsed (#2058). |
Interesting! I think we should unify this and either raise at compile time or at runtime depending on the proposed flag? |
I'm cool with a CLI flag to change behavior. Should we default to the most-Ruby-like behavior and have the flag enable "extra" checks? (In reality, the checks would be free, due to how we precompile, but that's probably counterintuitive for a user.)
I also like the idea of using the same approach for the regex check. |
I like this approach, staying as close to "normal" ruby behavior as possible! |
We implement eval with constant strings by compiling those strings during compile time. If an error occurs we fail compilation. This is a pretty nice feature of Natalie to ensure that code in evals is actually valid. However this also deviates from the behavior of ruby which only raises if the eval is actually called.
This is especially noticeable in our nightly spec runner. Currently there are at least 3 spec files that cannot compile because the spec explicitly tests that specific code raises a SyntaxError by using eval. One example:
What do you think about this?
The text was updated successfully, but these errors were encountered: