Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1875,13 +1875,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
Loading