fixes #22469; generates nimTestErrorFlag for top level statements (#22472)

fixes #22469; generates `nimTestErrorFlag` for top level statements

(cherry picked from commit 09d0fda7fd)
This commit is contained in:
ringabout
2023-08-14 19:08:01 +08:00
committed by narimiran
parent 814e929eeb
commit 2a4755ddf2
3 changed files with 22 additions and 2 deletions

View File

@@ -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", [])

View File

@@ -0,0 +1,4 @@
# ModuleB
echo "First top-level statement of ModuleB"
echo high(int) + 1
echo "ModuleB last statement"

View File

@@ -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