diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 49f4d68cfa..39be098663 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -2433,8 +2433,13 @@ proc genTopLevelStmt*(m: BModule; n: PNode) = else: genProcBody(m.initProc, transformedN) - for g in m.g.graph.procGlobals: - genStmts(m.preInitProc, g) + var procGloals = move m.g.graph.procGlobals + while true: + if procGloals.len == 0: + procGloals = move m.g.graph.procGlobals + if procGloals.len == 0: + break + genStmts(m.preInitProc, procGloals.pop()) proc shouldRecompile(m: BModule; code: Rope, cfile: Cfile): bool = if optForceFullMake notin m.config.globalOptions: diff --git a/tests/global/tglobal3.nim b/tests/global/tglobal3.nim index 10a40798f2..e0f0d50ce0 100644 --- a/tests/global/tglobal3.nim +++ b/tests/global/tglobal3.nim @@ -27,4 +27,17 @@ proc f(v: static string): int = xxx[] doAssert f("1") == 1 -doAssert f("1") == 1 \ No newline at end of file +doAssert f("1") == 1 + +block: # bug #24981 + func p(T: type): T {.compileTime.} = default(ptr T)[] + type W = ref object + proc g(T: type): W + proc m(T: type) = + let a {.global.} = g(T) + proc g(T: type): W = + when T is object: + m(typeof(p(T).i)) + type Foo = object + i: int + m(Foo)