Fixes #4222
This commit is contained in:
parent
ea0dff3783
commit
4d0d2d69f3
2 changed files with 16 additions and 5 deletions
|
|
@ -71,7 +71,7 @@ type
|
||||||
isLoop: bool # whether it's a 'block' or 'while'
|
isLoop: bool # whether it's a 'block' or 'while'
|
||||||
|
|
||||||
TGlobals = object
|
TGlobals = object
|
||||||
typeInfo, code: Rope
|
typeInfo, constants, code: Rope
|
||||||
forwarded: seq[PSym]
|
forwarded: seq[PSym]
|
||||||
generatedSyms: IntSet
|
generatedSyms: IntSet
|
||||||
typeInfoGenerated: IntSet
|
typeInfoGenerated: IntSet
|
||||||
|
|
@ -237,7 +237,7 @@ proc useMagic(p: PProc, name: string) =
|
||||||
internalAssert s.kind in {skProc, skMethod, skConverter}
|
internalAssert s.kind in {skProc, skMethod, skConverter}
|
||||||
if not p.g.generatedSyms.containsOrIncl(s.id):
|
if not p.g.generatedSyms.containsOrIncl(s.id):
|
||||||
let code = genProc(p, s)
|
let code = genProc(p, s)
|
||||||
add(p.g.code, code)
|
add(p.g.constants, code)
|
||||||
else:
|
else:
|
||||||
# we used to exclude the system module from this check, but for DLL
|
# we used to exclude the system module from this check, but for DLL
|
||||||
# generation support this sloppyness leads to hard to detect bugs, so
|
# generation support this sloppyness leads to hard to detect bugs, so
|
||||||
|
|
@ -1461,7 +1461,7 @@ proc genConstant(p: PProc, c: PSym) =
|
||||||
p.body = nil
|
p.body = nil
|
||||||
#genLineDir(p, c.ast)
|
#genLineDir(p, c.ast)
|
||||||
genVarInit(p, c, c.ast)
|
genVarInit(p, c, c.ast)
|
||||||
add(p.g.code, p.body)
|
add(p.g.constants, p.body)
|
||||||
p.body = oldBody
|
p.body = oldBody
|
||||||
|
|
||||||
proc genNew(p: PProc, n: PNode) =
|
proc genNew(p: PProc, n: PNode) =
|
||||||
|
|
@ -2137,7 +2137,7 @@ proc wholeCode*(m: BModule): Rope =
|
||||||
var p = newProc(globals, m, nil, m.module.options)
|
var p = newProc(globals, m, nil, m.module.options)
|
||||||
attachProc(p, prc)
|
attachProc(p, prc)
|
||||||
|
|
||||||
result = globals.typeInfo & globals.code
|
result = globals.typeInfo & globals.constants & globals.code
|
||||||
|
|
||||||
proc getClassName(t: PType): Rope =
|
proc getClassName(t: PType): Rope =
|
||||||
var s = t.sym
|
var s = t.sym
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''foo
|
output: '''foo
|
||||||
js 3.14
|
js 3.14
|
||||||
7'''
|
7
|
||||||
|
1'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# This file tests the JavaScript generator
|
# This file tests the JavaScript generator
|
||||||
|
|
@ -29,3 +30,13 @@ proc test(x: C, T: typedesc): T =
|
||||||
cast[T](x)
|
cast[T](x)
|
||||||
|
|
||||||
echo 7.test(int8)
|
echo 7.test(int8)
|
||||||
|
|
||||||
|
# #4222
|
||||||
|
const someConst = [ "1"]
|
||||||
|
|
||||||
|
proc procThatRefersToConst() # Forward decl
|
||||||
|
procThatRefersToConst() # Call bar before it is defined
|
||||||
|
|
||||||
|
proc procThatRefersToConst() =
|
||||||
|
var i = 0 # Use a var index, otherwise nim will constfold foo[0]
|
||||||
|
echo someConst[i] # JS exception here: foo is still not initialized (undefined)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue