Skip to content

Commit 646c4d1

Browse files
ringaboutnarimiran
authored andcommitted
fixes #22469; generates nimTestErrorFlag for top level statements (#22472)
fixes #22469; generates `nimTestErrorFlag` for top level statements (cherry picked from commit 09d0fda)
1 parent fd72df7 commit 646c4d1

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

compiler/cgen.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,13 +1890,13 @@ proc genInitCode(m: BModule) =
18901890
if beforeRetNeeded in m.initProc.flags:
18911891
prc.add("\tBeforeRet_: ;\n")
18921892

1893-
if sfMainModule in m.module.flags and m.config.exc == excGoto:
1893+
if m.config.exc == excGoto:
18941894
if getCompilerProc(m.g.graph, "nimTestErrorFlag") != nil:
18951895
m.appcg(prc, "\t#nimTestErrorFlag();$n", [])
18961896

18971897
if optStackTrace in m.initProc.options and preventStackTrace notin m.flags:
18981898
prc.add(deinitFrame(m.initProc))
1899-
elif sfMainModule in m.module.flags and m.config.exc == excGoto:
1899+
elif m.config.exc == excGoto:
19001900
if getCompilerProc(m.g.graph, "nimTestErrorFlag") != nil:
19011901
m.appcg(prc, "\t#nimTestErrorFlag();$n", [])
19021902

tests/exception/m22469.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# ModuleB
2+
echo "First top-level statement of ModuleB"
3+
echo high(int) + 1
4+
echo "ModuleB last statement"

tests/exception/t22469.nim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
discard """
2+
exitcode: 1
3+
output: '''
4+
First top-level statement of ModuleB
5+
m22469.nim(3) m22469
6+
fatal.nim(53) sysFatal
7+
Error: unhandled exception: over- or underflow [OverflowDefect]
8+
'''
9+
"""
10+
11+
# bug #22469
12+
13+
# ModuleA
14+
import m22469
15+
echo "ModuleA about to have exception"
16+
echo high(int) + 1

0 commit comments

Comments
 (0)