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.
sem: correctly show errors from
defer
node body
Summary ======= Errors in a defer node body are now correctly reported, no longer producing misleading `'defer' takes a 'void' expression` messages. Details ====== A`defer` with an error node body is no longer treated as an expression and having the underlying error supressed. Instead the body error is correctly reported. The `defer` AST is also correctly wrapped in an error node. A relatively comprehensive test sutie for `defer` statements was added, along with an improvement to the void expression error message requirement, which shows the `defer` body itself.
- Loading branch information
Showing
6 changed files
with
81 additions
and
4 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
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,34 @@ | ||
discard """ | ||
description: "Test for defer statements" | ||
""" | ||
|
||
block runs_at_the_end_of_scope: | ||
proc foo(): int = | ||
defer: | ||
inc result | ||
doAssert result == 0 | ||
|
||
doAssert foo() == 1 | ||
|
||
block questionably_not_at_the_end_of_proc_scope: | ||
proc foo(): int = | ||
if true: | ||
defer: | ||
inc result | ||
doAssert result == 0 | ||
doAssert result == 1 | ||
inc result | ||
doAssert result == 2 | ||
|
||
doAssert foo() == 2 | ||
|
||
block templates_do_not_create_scopes_defer_applies_to_the_surrounding: | ||
template bar() = | ||
defer: | ||
inc result | ||
|
||
proc foo(): int = | ||
bar() | ||
doAssert result == 0 | ||
|
||
doAssert foo() == 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,8 @@ | ||
discard """ | ||
description: "Defer cannot be decalred at the top level" | ||
errormsg: "defer statement not supported at top level" | ||
line: 7 | ||
""" | ||
|
||
defer: | ||
discard |
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,9 @@ | ||
discard """ | ||
description: "Defer body must be statement" | ||
errormsg: "'defer' takes a 'void' expression" | ||
line: 8 | ||
""" | ||
|
||
block: | ||
defer: | ||
true # this needs to be used |
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,13 @@ | ||
discard """ | ||
description: "Defer body must be a statement, without error" | ||
errormsg: "type mismatch: got <bool, int literal(1)>" | ||
line: 12 | ||
""" | ||
|
||
## somewhat of a regression test to see what happens when the defer body has an | ||
## error, this was an issue encountered in CPS, where an error body was treated | ||
## as an expression. | ||
|
||
block: | ||
defer: | ||
true + 1 |