Skip to content

Commit

Permalink
fixes #22469; generates nimTestErrorFlag for top level statements (#2…
Browse files Browse the repository at this point in the history
…2472)

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

(cherry picked from commit 09d0fda)
  • Loading branch information
ringabout authored and narimiran committed Apr 17, 2024
1 parent 814e929 commit 2a4755d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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", [])

Expand Down
4 changes: 4 additions & 0 deletions tests/exception/m22469.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ModuleB
echo "First top-level statement of ModuleB"
echo high(int) + 1
echo "ModuleB last statement"
16 changes: 16 additions & 0 deletions tests/exception/t22469.nim
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2a4755d

Please sign in to comment.