mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
Fixes #4222
This commit is contained in:
@@ -71,7 +71,7 @@ type
|
||||
isLoop: bool # whether it's a 'block' or 'while'
|
||||
|
||||
TGlobals = object
|
||||
typeInfo, code: Rope
|
||||
typeInfo, constants, code: Rope
|
||||
forwarded: seq[PSym]
|
||||
generatedSyms: IntSet
|
||||
typeInfoGenerated: IntSet
|
||||
@@ -237,7 +237,7 @@ proc useMagic(p: PProc, name: string) =
|
||||
internalAssert s.kind in {skProc, skMethod, skConverter}
|
||||
if not p.g.generatedSyms.containsOrIncl(s.id):
|
||||
let code = genProc(p, s)
|
||||
add(p.g.code, code)
|
||||
add(p.g.constants, code)
|
||||
else:
|
||||
# we used to exclude the system module from this check, but for DLL
|
||||
# generation support this sloppyness leads to hard to detect bugs, so
|
||||
@@ -1461,7 +1461,7 @@ proc genConstant(p: PProc, c: PSym) =
|
||||
p.body = nil
|
||||
#genLineDir(p, c.ast)
|
||||
genVarInit(p, c, c.ast)
|
||||
add(p.g.code, p.body)
|
||||
add(p.g.constants, p.body)
|
||||
p.body = oldBody
|
||||
|
||||
proc genNew(p: PProc, n: PNode) =
|
||||
@@ -2137,7 +2137,7 @@ proc wholeCode*(m: BModule): Rope =
|
||||
var p = newProc(globals, m, nil, m.module.options)
|
||||
attachProc(p, prc)
|
||||
|
||||
result = globals.typeInfo & globals.code
|
||||
result = globals.typeInfo & globals.constants & globals.code
|
||||
|
||||
proc getClassName(t: PType): Rope =
|
||||
var s = t.sym
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
discard """
|
||||
output: '''foo
|
||||
js 3.14
|
||||
7'''
|
||||
7
|
||||
1'''
|
||||
"""
|
||||
|
||||
# This file tests the JavaScript generator
|
||||
@@ -29,3 +30,13 @@ proc test(x: C, T: typedesc): T =
|
||||
cast[T](x)
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user