-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sem): analysis considers nested noreturn (#1450)
## Summary No-return analysis ensures that nested final expressions ( `block/case/if/try` ) are accounted for no-return itself. ## Details Prior to this change if the last expression within a greater expression was a no-return expression it would not be deemed as such if it was a `block/case/if/try` , instead errors would be raised related to discard checks or that path not resulting in the correct type. For example, the following would result in an error where `0` must be used or discarded: ```nim proc foo() = let x = if false: 10 else: block: return ``` Fixes #1440 --------- Co-authored-by: zerbina <[email protected]>
- Loading branch information
Showing
4 changed files
with
65 additions
and
9 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
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,53 @@ | ||
discard """ | ||
description: ''' | ||
Ensure nested noreturn statements are considererd in noreturn analysis | ||
''' | ||
""" | ||
|
||
block nested_in_if: | ||
let x = | ||
if true: | ||
0 | ||
else: | ||
if true: | ||
raise newException(CatchableError, "error") | ||
else: | ||
raise newException(CatchableError, "another error") | ||
|
||
doAssert x is int | ||
|
||
block nested_in_try: | ||
let x = | ||
if true: | ||
0 | ||
else: | ||
try: | ||
raise newException(CatchableError, "error") | ||
finally: | ||
discard | ||
|
||
doAssert x is int | ||
|
||
block nested_in_case: | ||
let x = | ||
if true: | ||
0 | ||
else: | ||
let s = false | ||
case s | ||
of true: | ||
raise newException(CatchableError, "error") | ||
of false: | ||
raise newException(CatchableError, "another error") | ||
|
||
doAssert x is int | ||
|
||
block nested_in_block: | ||
let x = | ||
if true: | ||
0 | ||
else: | ||
block: | ||
raise newException(CatchableError, "error") | ||
|
||
doAssert x is int |