summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2023-01-24 22:37:22 +0800
committerGitHub <noreply@github.com>2023-01-24 15:37:22 +0100
commitd54a7f078d29445bc79ec5f117a2ceb73761b4c4 (patch)
tree6379e900a923f5873eef9f6967f12cabac4957c6
parent5e7f7109e19b33bc142aa7b06e9044420232a578 (diff)
downloadNim-d54a7f078d29445bc79ec5f117a2ceb73761b4c4.tar.gz
fixes #21261; always checking `nimTestErrorFlag` in the main module (#21288)
* fixes #21261; always checking nimTestErrorFlag in the main module

* add a test
-rw-r--r--compiler/cgen.nim3
-rw-r--r--tests/exception/m21261.nim1
-rw-r--r--tests/exception/t21261.nim9
3 files changed, 13 insertions, 0 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index f6457f1e0..5bf9400c5 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 000000000..11b12fb5b
--- /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 000000000..84817d854
--- /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