-
Notifications
You must be signed in to change notification settings - Fork 188
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
Reject certain code that should return but doesn't #502
Conversation
@@ -3,4 +3,4 @@ contract Foo: | |||
if val > 1: | |||
return 5 | |||
else: | |||
x = 1 |
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.
This was an extra error in the test file that I think we didn't intent to test for here
2f5cff9
to
17e434f
Compare
Codecov Report
@@ Coverage Diff @@
## master #502 +/- ##
==========================================
- Coverage 87.72% 87.69% -0.03%
==========================================
Files 80 80
Lines 5272 5276 +4
==========================================
+ Hits 4625 4627 +2
- Misses 647 649 +2
Continue to review full report at Codecov.
|
@@ -174,7 +174,7 @@ fn all_paths_return_or_revert(block: &[Node<fe::FuncStmt>]) -> bool { | |||
or_else, | |||
} => { | |||
let body_returns = all_paths_return_or_revert(body); | |||
let or_else_returns = or_else.is_empty() || all_paths_return_or_revert(or_else); | |||
let or_else_returns = !or_else.is_empty() && all_paths_return_or_revert(or_else); |
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.
we could just get rid of the is_empty
check, as all_paths_return_or_revert(or_else)
will return false for an empty vec
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.
Ah sure, I'll get that updated 👍
17e434f
to
f4ddda2
Compare
What was wrong?
As described in #497 the following code does compile in master but should generate a user error instead. It needs to error because the code is missing a return statement since it is not guaranteed that the execution follows the arm of the
if
statement.How was it fixed?
The check in
all_paths_return_or_revert
is wrong because it counts a missingelse
branch as if the code returns when clearly a missingelse
branch shouldn't indicate such thing.