-
Notifications
You must be signed in to change notification settings - Fork 39
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
only allow re-raise in scope of except
#1170
Merged
chore-runner
merged 6 commits into
nim-works:devel
from
zerbina:disallow-reraise-outside-except
Feb 7, 2024
Merged
only allow re-raise in scope of except
#1170
chore-runner
merged 6 commits into
nim-works:devel
from
zerbina:disallow-reraise-outside-except
Feb 7, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`track` keeps track of whether directly inside a except, and only allows a re-raise statement when this is the case. A new report is added for the error.
The `reraiseInFinally` test case explicitly tested the now-disallowed usage. It is removed.
The `t18203_consumed_ast_is_not_unused` test made use of the now- disallowed `raise` usage, but it didn't rely on the functionality. The re-raise is replaced with a normal `raise` statement.
zerbina
added
compiler/sem
Related to semantic-analysis system of the compiler
language-design
Language design syntax, semantics, types, statics and dynamics.
labels
Feb 6, 2024
saem
approved these changes
Feb 6, 2024
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.
Minor suggestion for additional test coverage, but perhaps it's sufficiently covered in tfinally6.exceptionInFinally
-- feel free to ignore it.
Co-authored-by: Saem Ghani <saemghani+github@gmail.com>
/merge |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
compiler/sem
Related to semantic-analysis system of the compiler
language-design
Language design syntax, semantics, types, statics and dynamics.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Treat a re-raise (i.e.,
raise
without operand) as a compile-timeerror when used outside of the scope of an
except
clause -- re-raising from within a
finally
clause that's within the scope of anexcept
clause is disallowed too.This brings the re-raise feature into a "safe" state, where it can be
extended from again if wanted/needed.
Details
If a re-raise is allowed from anywhere, it is possible to handle an in-
flight exception from within a
finally
clause:Since the exception is handled, control-flow would have to "fall out"
of the
finally
clause, but this violates the expectations of control-flow analysis in the compiler as well as those of the code generators.
There, the expectation is that if a
finally
clause was enteredthrough exceptional control-flow, raising continues when the end of
the
finally
is reached.Until it's clear if, how, and under what circumstances this should
work, a
finally
clause handling the in-flight exception is preventedby restricting re-raise statements to the scope of
except
clauses.sempass2
implements the detection and error reporting.The manual is updated accordingly and tests for the new behaviour are
added.
Usage
In the compiler's repository, re-raising from outside the scope of an
except
clause was only done by two tests. For one of them, the re-raise can safely be replaced with a normal
raise
.The other test explicitly tested the "re-raise in finally" case. It is
removed for now.