diff options
author | Tanguy <tanguy@status.im> | 2022-10-24 07:57:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-24 07:57:49 +0200 |
commit | 4578e773ce9e48ca038ee23f25509dfbc7e7db95 (patch) | |
tree | 98d62a3c942cce1e6e5f2429cdd1381b7524fca4 | |
parent | 6d8178a93e14f24cbb327cf718de181942339126 (diff) | |
download | Nim-4578e773ce9e48ca038ee23f25509dfbc7e7db95.tar.gz |
Remove side-effects from sysFatal with panics on (#20632)
-rw-r--r-- | lib/system/fatal.nim | 33 | ||||
-rw-r--r-- | tests/exception/t20613.nim | 8 |
2 files changed, 25 insertions, 16 deletions
diff --git a/lib/system/fatal.nim b/lib/system/fatal.nim index 64ec9cda3..c01787a32 100644 --- a/lib/system/fatal.nim +++ b/lib/system/fatal.nim @@ -17,42 +17,43 @@ else: when hostOS == "standalone": include "$projectpath/panicoverride" - proc sysFatal(exceptn: typedesc, message: string) {.inline.} = + func sysFatal(exceptn: typedesc, message: string) {.inline.} = panic(message) - proc sysFatal(exceptn: typedesc, message, arg: string) {.inline.} = + func sysFatal(exceptn: typedesc, message, arg: string) {.inline.} = rawoutput(message) panic(arg) elif (defined(nimQuirky) or defined(nimPanics)) and not defined(nimscript): import ansi_c - proc name(t: typedesc): string {.magic: "TypeTrait".} + func name(t: typedesc): string {.magic: "TypeTrait".} - proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} = + func sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} = when nimvm: # TODO when doAssertRaises works in CT, add a test for it raise (ref exceptn)(msg: message & arg) else: - writeStackTrace() - var buf = newStringOfCap(200) - add(buf, "Error: unhandled exception: ") - add(buf, message) - add(buf, arg) - add(buf, " [") - add(buf, name exceptn) - add(buf, "]\n") - cstderr.rawWrite buf + {.noSideEffect.}: + writeStackTrace() + var buf = newStringOfCap(200) + add(buf, "Error: unhandled exception: ") + add(buf, message) + add(buf, arg) + add(buf, " [") + add(buf, name exceptn) + add(buf, "]\n") + cstderr.rawWrite buf quit 1 - proc sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} = + func sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} = sysFatal(exceptn, message, "") else: - proc sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} = + func sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} = raise (ref exceptn)(msg: message) - proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} = + func sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} = raise (ref exceptn)(msg: message & arg) {.pop.} diff --git a/tests/exception/t20613.nim b/tests/exception/t20613.nim new file mode 100644 index 000000000..6edb69415 --- /dev/null +++ b/tests/exception/t20613.nim @@ -0,0 +1,8 @@ +discard """ + matrix: "; --panics:on" +""" + +func test = + if 0 > 10: + raiseAssert "hey" +test() |