Skip to content

Commit ffb993d

Browse files
authored
fixes #24981; the length of the seq changed of procGloals (#24984)
fxies #24981 `m.g.graph.procGlobals` could change because the right side of `.global` assignment (e.g. `let a {.global.} = g(T)`) may trigger injections for unhandled procs
1 parent d27c215 commit ffb993d

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

compiler/cgen.nim

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,8 +2433,13 @@ proc genTopLevelStmt*(m: BModule; n: PNode) =
24332433
else:
24342434
genProcBody(m.initProc, transformedN)
24352435

2436-
for g in m.g.graph.procGlobals:
2437-
genStmts(m.preInitProc, g)
2436+
var procGloals = move m.g.graph.procGlobals
2437+
while true:
2438+
if procGloals.len == 0:
2439+
procGloals = move m.g.graph.procGlobals
2440+
if procGloals.len == 0:
2441+
break
2442+
genStmts(m.preInitProc, procGloals.pop())
24382443

24392444
proc shouldRecompile(m: BModule; code: Rope, cfile: Cfile): bool =
24402445
if optForceFullMake notin m.config.globalOptions:

tests/global/tglobal3.nim

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,17 @@ proc f(v: static string): int =
2727
xxx[]
2828

2929
doAssert f("1") == 1
30-
doAssert f("1") == 1
30+
doAssert f("1") == 1
31+
32+
block: # bug #24981
33+
func p(T: type): T {.compileTime.} = default(ptr T)[]
34+
type W = ref object
35+
proc g(T: type): W
36+
proc m(T: type) =
37+
let a {.global.} = g(T)
38+
proc g(T: type): W =
39+
when T is object:
40+
m(typeof(p(T).i))
41+
type Foo = object
42+
i: int
43+
m(Foo)

0 commit comments

Comments
 (0)