fixes #9864 [backport]
This commit is contained in:
parent
24106ade8f
commit
af815c3c18
2 changed files with 51 additions and 5 deletions
|
|
@ -31,10 +31,18 @@ proc intLiteral(i: BiggestInt): Rope =
|
||||||
result = ~"(IL64(-9223372036854775807) - IL64(1))"
|
result = ~"(IL64(-9223372036854775807) - IL64(1))"
|
||||||
|
|
||||||
proc genLiteral(p: BProc, n: PNode, ty: PType): Rope =
|
proc genLiteral(p: BProc, n: PNode, ty: PType): Rope =
|
||||||
if ty == nil: internalError(p.config, n.info, "genLiteral: ty is nil")
|
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkCharLit..nkUInt64Lit:
|
of nkCharLit..nkUInt64Lit:
|
||||||
case skipTypes(ty, abstractVarRange).kind
|
var k: TTypeKind
|
||||||
|
if ty != nil:
|
||||||
|
k = skipTypes(ty, abstractVarRange).kind
|
||||||
|
else:
|
||||||
|
case n.kind
|
||||||
|
of nkCharLit: k = tyChar
|
||||||
|
of nkUInt64Lit: k = tyUInt64
|
||||||
|
of nkInt64Lit: k = tyInt64
|
||||||
|
else: k = tyNil # don't go into the case variant that uses 'ty'
|
||||||
|
case k
|
||||||
of tyChar, tyNil:
|
of tyChar, tyNil:
|
||||||
result = intLiteral(n.intVal)
|
result = intLiteral(n.intVal)
|
||||||
of tyBool:
|
of tyBool:
|
||||||
|
|
@ -46,8 +54,8 @@ proc genLiteral(p: BProc, n: PNode, ty: PType): Rope =
|
||||||
result = "(($1) $2)" % [getTypeDesc(p.module,
|
result = "(($1) $2)" % [getTypeDesc(p.module,
|
||||||
ty), intLiteral(n.intVal)]
|
ty), intLiteral(n.intVal)]
|
||||||
of nkNilLit:
|
of nkNilLit:
|
||||||
let t = skipTypes(ty, abstractVarRange)
|
let k = if ty == nil: tyPointer else: skipTypes(ty, abstractVarRange).kind
|
||||||
if t.kind == tyProc and t.callConv == ccClosure:
|
if k == tyProc and skipTypes(ty, abstractVarRange).callConv == ccClosure:
|
||||||
let id = nodeTableTestOrSet(p.module.dataCache, n, p.module.labels)
|
let id = nodeTableTestOrSet(p.module.dataCache, n, p.module.labels)
|
||||||
result = p.module.tmpBase & rope(id)
|
result = p.module.tmpBase & rope(id)
|
||||||
if id == p.module.labels:
|
if id == p.module.labels:
|
||||||
|
|
@ -59,7 +67,9 @@ proc genLiteral(p: BProc, n: PNode, ty: PType): Rope =
|
||||||
else:
|
else:
|
||||||
result = rope("NIM_NIL")
|
result = rope("NIM_NIL")
|
||||||
of nkStrLit..nkTripleStrLit:
|
of nkStrLit..nkTripleStrLit:
|
||||||
case skipTypes(ty, abstractVarRange + {tyStatic, tyUserTypeClass, tyUserTypeClassInst}).kind
|
let k = if ty == nil: tyString
|
||||||
|
else: skipTypes(ty, abstractVarRange + {tyStatic, tyUserTypeClass, tyUserTypeClassInst}).kind
|
||||||
|
case k
|
||||||
of tyNil:
|
of tyNil:
|
||||||
result = genNilStringLiteral(p.module, n.info)
|
result = genNilStringLiteral(p.module, n.info)
|
||||||
of tyString:
|
of tyString:
|
||||||
|
|
|
||||||
36
tests/macros/tescape_var_into_quotedo_as_const.nim
Normal file
36
tests/macros/tescape_var_into_quotedo_as_const.nim
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
discard """
|
||||||
|
output: '''ok'''
|
||||||
|
"""
|
||||||
|
# bug #9864
|
||||||
|
import macros, tables
|
||||||
|
|
||||||
|
proc bar(shOpt: Table[string, int]) = discard
|
||||||
|
|
||||||
|
macro dispatchGen(): untyped =
|
||||||
|
var shOpt = initTable[string, int]()
|
||||||
|
shOpt["foo"] = 10
|
||||||
|
result = quote do:
|
||||||
|
bar(`shOpt`)
|
||||||
|
|
||||||
|
dispatchGen()
|
||||||
|
|
||||||
|
type
|
||||||
|
Foo = object
|
||||||
|
data: seq[int]
|
||||||
|
|
||||||
|
proc barB(a: Foo) = discard
|
||||||
|
|
||||||
|
proc shOptB(): auto =
|
||||||
|
var shOpt: Foo
|
||||||
|
shOpt.data.setLen 1 # fails
|
||||||
|
shOpt
|
||||||
|
|
||||||
|
macro dispatchGenB(): untyped =
|
||||||
|
var shOpt = shOptB() # fails
|
||||||
|
|
||||||
|
result = quote do:
|
||||||
|
barB(`shOpt`)
|
||||||
|
|
||||||
|
dispatchGenB()
|
||||||
|
|
||||||
|
echo "ok"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue