forked from nim-works/nimskull
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Summary A missing `discard` in a `try/finally` no longer crashes the compiler and emits an error as it should. ## Details The `discardCheck` used to ensure expressions are used or `void` did not traverse `try` appropriately. Instead of looking at the last expression in the last `except` or `try` branch, it would look at the last branch, even if that was a `finally`. This led to incomplete data being sent for error reporting, which ultimately led to an NPE. Along with the fix a regression test has been added.
- Loading branch information
Showing
3 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
discard """ | ||
description: "Ensure discard checks are done for try expressions" | ||
errormsg: "expression '1' is of type 'int literal(1)' and has to be used (or discarded)" | ||
line: 14 | ||
""" | ||
|
||
## This was originally introduced as a regression test, where a fix to | ||
## `semstmts.discardCheck` erroneously changed traversals in a manner where | ||
## the test suite passed but this was not caught, except in code review. | ||
|
||
try: | ||
discard | ||
except: | ||
1 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
discard """ | ||
description: "Ensure discard checks are done for try expressions" | ||
errormsg: "expression '1' is of type 'int literal(1)' and has to be used (or discarded)" | ||
line: 14 | ||
""" | ||
|
||
## This was originally introduced as a regression test, where | ||
## `semstmts.discardCheck` erroneously checked the `finally` branch, instead | ||
## of the last non-`finally` branch in the `try` expression. This generated an | ||
## incomplete report, and resulted in an NPE within `cli_reporter` when | ||
## attempting to render it. | ||
|
||
try: | ||
1 | ||
finally: | ||
discard 1 |