Remove side-effects from sysFatal with panics on (#20632)
This commit is contained in:
parent
6d8178a93e
commit
4578e773ce
2 changed files with 25 additions and 16 deletions
|
|
@ -17,23 +17,24 @@ else:
|
||||||
when hostOS == "standalone":
|
when hostOS == "standalone":
|
||||||
include "$projectpath/panicoverride"
|
include "$projectpath/panicoverride"
|
||||||
|
|
||||||
proc sysFatal(exceptn: typedesc, message: string) {.inline.} =
|
func sysFatal(exceptn: typedesc, message: string) {.inline.} =
|
||||||
panic(message)
|
panic(message)
|
||||||
|
|
||||||
proc sysFatal(exceptn: typedesc, message, arg: string) {.inline.} =
|
func sysFatal(exceptn: typedesc, message, arg: string) {.inline.} =
|
||||||
rawoutput(message)
|
rawoutput(message)
|
||||||
panic(arg)
|
panic(arg)
|
||||||
|
|
||||||
elif (defined(nimQuirky) or defined(nimPanics)) and not defined(nimscript):
|
elif (defined(nimQuirky) or defined(nimPanics)) and not defined(nimscript):
|
||||||
import ansi_c
|
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:
|
when nimvm:
|
||||||
# TODO when doAssertRaises works in CT, add a test for it
|
# TODO when doAssertRaises works in CT, add a test for it
|
||||||
raise (ref exceptn)(msg: message & arg)
|
raise (ref exceptn)(msg: message & arg)
|
||||||
else:
|
else:
|
||||||
|
{.noSideEffect.}:
|
||||||
writeStackTrace()
|
writeStackTrace()
|
||||||
var buf = newStringOfCap(200)
|
var buf = newStringOfCap(200)
|
||||||
add(buf, "Error: unhandled exception: ")
|
add(buf, "Error: unhandled exception: ")
|
||||||
|
|
@ -45,14 +46,14 @@ elif (defined(nimQuirky) or defined(nimPanics)) and not defined(nimscript):
|
||||||
cstderr.rawWrite buf
|
cstderr.rawWrite buf
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
proc sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
|
func sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
|
||||||
sysFatal(exceptn, message, "")
|
sysFatal(exceptn, message, "")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
proc sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
|
func sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
|
||||||
raise (ref exceptn)(msg: message)
|
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)
|
raise (ref exceptn)(msg: message & arg)
|
||||||
|
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
|
||||||
8
tests/exception/t20613.nim
Normal file
8
tests/exception/t20613.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
discard """
|
||||||
|
matrix: "; --panics:on"
|
||||||
|
"""
|
||||||
|
|
||||||
|
func test =
|
||||||
|
if 0 > 10:
|
||||||
|
raiseAssert "hey"
|
||||||
|
test()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue