Skip to content
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

Closed

Conversation

addisoncrump
Copy link
Contributor

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

@codecov
Copy link

codecov bot commented Feb 23, 2022

Codecov Report

Merging #1860 (58fd56a) into main (44b5617) will increase coverage by 0.00%.
The diff coverage is 66.66%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1860   +/-   ##
=======================================
  Coverage   46.04%   46.04%           
=======================================
  Files         206      206           
  Lines       17003    17005    +2     
=======================================
+ Hits         7829     7830    +1     
- Misses       9174     9175    +1     
Impacted Files Coverage Δ
boa_engine/src/bytecompiler.rs 37.22% <66.66%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44b5617...58fd56a. Read the comment docs.

Copy link
Member

@Razican Razican left a 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

break;
"#;

assert!(matches!(Context::default().eval(src.as_bytes()), Err(_)));
Copy link
Member

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.

Copy link
Member

@HalidOdat HalidOdat left a 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.

@HalidOdat HalidOdat added the bug Something isn't working label Feb 23, 2022
@Razican
Copy link
Member

Razican commented Feb 23, 2022

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.

@HalidOdat
Copy link
Member

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 FIXMEs in places where we have the quick fix, so we can deal with them later :)

@Razican
Copy link
Member

Razican commented Feb 23, 2022

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 FIXMEs in places where we have the quick fix, so we can deal with them later :)

Maybe also to open n issue about it

@raskad
Copy link
Member

raskad commented Feb 23, 2022

In which case it should be in the parser, not compilation.

#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.

@addisoncrump
Copy link
Contributor Author

Are the changes requested still relevant? I'm not sure what I need to change here.

@Razican Razican requested a review from HalidOdat March 5, 2022 21:59
@raskad
Copy link
Member

raskad commented Mar 7, 2022

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.

bors bot pushed a commit that referenced this pull request Mar 8, 2022
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.
@raskad
Copy link
Member

raskad commented Mar 8, 2022

@HalidOdat Can you give this another look so we can fix those panics on main?

@HalidOdat
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Mar 8, 2022
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
@bors
Copy link

bors bot commented Mar 8, 2022

Pull request successfully merged into main.

Build succeeded:

@bors bors bot changed the title Prevent breaks without loop or switch from causing panics [Merged by Bors] - Prevent breaks without loop or switch from causing panics Mar 8, 2022
@bors bors bot closed this Mar 8, 2022
@Razican Razican added this to the v0.14.0 milestone Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants