-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
[Merged by Bors] - Prevent breaks without loop or switch from causing panics #1860
[Merged by Bors] - Prevent breaks without loop or switch from causing panics #1860
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1860 +/- ##
=======================================
Coverage 46.04% 46.04%
=======================================
Files 206 206
Lines 17003 17005 +2
=======================================
+ Hits 7829 7830 +1
- Misses 9174 9175 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small recommendation for readability
boa_engine/src/tests.rs
Outdated
break; | ||
"#; | ||
|
||
assert!(matches!(Context::default().eval(src.as_bytes()), Err(_))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too, I would use is_err()
instead of matches!()
, it makes things more clear, and you can directly pass a reference to src
instead of calling as_bytes()
, if I remember correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm... Shouldn't this be an early error . According to spec:
14.9.1 Static Semantics: Early Errors
BreakStatement: break ;It is a Syntax Error if this BreakStatement is not nested, directly or indirectly (but not crossing function or static initialization block boundaries), within an IterationStatement or a SwitchStatement.
In which case it should be in the parser, not compilation.
Indeed, this should be in the parser, but that might be a bit more complex to implement, so this could be a quick win to avoid the panic for the 0.14 release. |
In that case we should put |
Maybe also to open n issue about it |
#1829 also introduces syntax errors at compilation time. I'm not sure if it makes sense to push all of these errors to the parser. For some we would have to walk the whole AST, and we do that at compilation time anyways. |
Are the changes requested still relevant? I'm not sure what I need to change here. |
The changes are still relevant. Can you rebase the branch on main? @HalidOdat I created #1907 to track the progress on compile time errors. |
This fixes an issue with 262 negative tests, that should produce a syntax errors. Currently we only parse the test code is such cases. If the parsing does not return an error, we do not compile the code further. This caused some panics. Most of them are fixed by now, the last ones will be fixed with #1860.
@HalidOdat Can you give this another look so we can fix those panics on main? |
bors r+ |
This PR changes the following: - Replaces a panic with a syntax error when a break is used outside of a loop or switch - Adds a test for that
Pull request successfully merged into main. Build succeeded: |
This PR changes the following: