From d54a7f078d29445bc79ec5f117a2ceb73761b4c4 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 24 Jan 2023 22:37:22 +0800 Subject: [PATCH] fixes #21261; always checking `nimTestErrorFlag` in the main module (#21288) * fixes #21261; always checking nimTestErrorFlag in the main module * add a test --- compiler/cgen.nim | 3 +++ tests/exception/m21261.nim | 1 + tests/exception/t21261.nim | 9 +++++++++ 3 files changed, 13 insertions(+) create mode 100644 tests/exception/m21261.nim create mode 100644 tests/exception/t21261.nim diff --git a/compiler/cgen.nim b/compiler/cgen.nim index f6457f1e01..5bf9400c51 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -1801,6 +1801,9 @@ proc genInitCode(m: BModule) = if optStackTrace in m.initProc.options and preventStackTrace notin m.flags: prc.add(deinitFrame(m.initProc)) + elif sfMainModule in m.module.flags and m.config.exc == excGoto: + if getCompilerProc(m.g.graph, "nimTestErrorFlag") != nil: + m.appcg(prc, "\t#nimTestErrorFlag();$n", []) prc.addf("}$N", []) diff --git a/tests/exception/m21261.nim b/tests/exception/m21261.nim new file mode 100644 index 0000000000..11b12fb5b9 --- /dev/null +++ b/tests/exception/m21261.nim @@ -0,0 +1 @@ +raise (ref Exception)(msg: "something") \ No newline at end of file diff --git a/tests/exception/t21261.nim b/tests/exception/t21261.nim new file mode 100644 index 0000000000..84817d854d --- /dev/null +++ b/tests/exception/t21261.nim @@ -0,0 +1,9 @@ +discard """ + exitcode: 1 + outputsub: ''' +m21261.nim(1) m21261 +Error: unhandled exception: something [Exception] +''' +""" + +import m21261 \ No newline at end of file