mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-12 06:18:51 +00:00
fixes #24997
handles functions in recursive order
(cherry picked from commit 3ce38f2959)
This commit is contained in:
@@ -2170,6 +2170,20 @@ proc addHcrInitGuards(p: BProc, n: PNode, inInitGuard: var bool) =
|
||||
|
||||
genStmts(p, n)
|
||||
|
||||
proc handleProcGlobals(m: BModule) =
|
||||
var procGlobals: seq[PNode] = move m.g.graph.procGlobals
|
||||
|
||||
for i in 0..<procGlobals.len:
|
||||
var stmts = newBuilder("")
|
||||
|
||||
# fixes recursive calls #24997
|
||||
swap stmts, m.preInitProc.s(cpsStmts)
|
||||
genStmts(m.preInitProc, procGlobals[i])
|
||||
swap stmts, m.preInitProc.s(cpsStmts)
|
||||
|
||||
handleProcGlobals(m)
|
||||
m.preInitProc.s(cpsStmts).add stmts.extract()
|
||||
|
||||
proc genTopLevelStmt*(m: BModule; n: PNode) =
|
||||
## Also called from `ic/cbackend.nim`.
|
||||
if pipelineutils.skipCodegen(m.config, n): return
|
||||
@@ -2185,13 +2199,7 @@ proc genTopLevelStmt*(m: BModule; n: PNode) =
|
||||
else:
|
||||
genProcBody(m.initProc, transformedN)
|
||||
|
||||
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())
|
||||
handleProcGlobals(m)
|
||||
|
||||
proc shouldRecompile(m: BModule; code: Rope, cfile: Cfile): bool =
|
||||
if optForceFullMake notin m.config.globalOptions:
|
||||
|
||||
@@ -41,3 +41,17 @@ block: # bug #24981
|
||||
type Foo = object
|
||||
i: int
|
||||
m(Foo)
|
||||
|
||||
block: # bug #24997
|
||||
type R = ref object
|
||||
type B = object
|
||||
j: int
|
||||
proc y(T: type): R
|
||||
proc u(T: type): R =
|
||||
let res {.global.} = y(T)
|
||||
res
|
||||
proc y(T: type): R =
|
||||
when T is object:
|
||||
doAssert not isNil(u(typeof(B.j)))
|
||||
R()
|
||||
discard u(B)
|
||||
|
||||
Reference in New Issue
Block a user