From 2a4755ddf2cb42875a2c59652252dc4ed318d077 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Mon, 14 Aug 2023 19:08:01 +0800 Subject: [PATCH] fixes #22469; generates nimTestErrorFlag for top level statements (#22472) fixes #22469; generates `nimTestErrorFlag` for top level statements (cherry picked from commit 09d0fda7fde69087c75a102b219d5eebf1b86db2) --- compiler/cgen.nim | 4 ++-- tests/exception/m22469.nim | 4 ++++ tests/exception/t22469.nim | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/exception/m22469.nim create mode 100644 tests/exception/t22469.nim diff --git a/compiler/cgen.nim b/compiler/cgen.nim index d71896ef8c..f4a02db618 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -1890,13 +1890,13 @@ proc genInitCode(m: BModule) = if beforeRetNeeded in m.initProc.flags: prc.add("\tBeforeRet_: ;\n") - if sfMainModule in m.module.flags and m.config.exc == excGoto: + if m.config.exc == excGoto: if getCompilerProc(m.g.graph, "nimTestErrorFlag") != nil: m.appcg(prc, "\t#nimTestErrorFlag();$n", []) 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: + elif m.config.exc == excGoto: if getCompilerProc(m.g.graph, "nimTestErrorFlag") != nil: m.appcg(prc, "\t#nimTestErrorFlag();$n", []) diff --git a/tests/exception/m22469.nim b/tests/exception/m22469.nim new file mode 100644 index 0000000000..2016987015 --- /dev/null +++ b/tests/exception/m22469.nim @@ -0,0 +1,4 @@ +# ModuleB +echo "First top-level statement of ModuleB" +echo high(int) + 1 +echo "ModuleB last statement" \ No newline at end of file diff --git a/tests/exception/t22469.nim b/tests/exception/t22469.nim new file mode 100644 index 0000000000..a76c749678 --- /dev/null +++ b/tests/exception/t22469.nim @@ -0,0 +1,16 @@ +discard """ + exitcode: 1 + output: ''' +First top-level statement of ModuleB +m22469.nim(3) m22469 +fatal.nim(53) sysFatal +Error: unhandled exception: over- or underflow [OverflowDefect] +''' +""" + +# bug #22469 + +# ModuleA +import m22469 +echo "ModuleA about to have exception" +echo high(int) + 1