diff options
author | Jake Leahy <jake@leahy.dev> | 2023-12-17 22:29:46 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-17 12:29:46 +0100 |
commit | b3b87f0f8a8091c88461953d686f9772dfb3c4bc (patch) | |
tree | 8ef9fcd765ce6c0927ba4d3e394b688946193488 /lib | |
parent | 0bd4d802383518cfbb43fa02375602abdfb6114f (diff) | |
download | Nim-b3b87f0f8a8091c88461953d686f9772dfb3c4bc.tar.gz |
Mark `macros.error` as `.noreturn.` (#23081)
Closes #14329 Marks `macros.error` as `.noreturn` so that it can be used in expressions. This also fixes the issue that occurred in #19659 where a stmt that could be an expression (Due to having `discardable` procs at the end of other branches) would believe a `noreturn` proc is returning the same type e.g. ```nim proc bar(): int {.discardable.} = discard if true: bar() else: quit(0) # Says that quit is of type `int` and needs to be used/discarded except it actually has no return type ```
Diffstat (limited to 'lib')
-rw-r--r-- | lib/core/macros.nim | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 01a654b6c..fe911ffbf 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -427,7 +427,12 @@ proc copyNimTree*(n: NimNode): NimNode {.magic: "NCopyNimTree", noSideEffect.} = let x = 12 echo x -proc error*(msg: string, n: NimNode = nil) {.magic: "NError", benign.} +when defined(nimHasNoReturnError): + {.pragma: errorNoReturn, noreturn.} +else: + {.pragma: errorNoReturn.} + +proc error*(msg: string, n: NimNode = nil) {.magic: "NError", benign, errorNoReturn.} ## Writes an error message at compile time. The optional `n: NimNode` ## parameter is used as the source for file and line number information in ## the compilation error message. |