mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
fixes #926
This commit is contained in:
@@ -916,23 +916,28 @@ proc requiresCopy(n: PNode): bool =
|
||||
proc unneededIndirection(n: PNode): bool =
|
||||
n.typ.skipTypes(abstractInst-{tyTypeDesc}).kind == tyRef
|
||||
|
||||
proc skipDeref(n: PNode): PNode =
|
||||
if n.kind in {nkDerefExpr, nkHiddenDeref} and unneededIndirection(n.sons[0]):
|
||||
result = n.sons[0]
|
||||
else:
|
||||
result = n
|
||||
|
||||
proc genAddrDeref(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode;
|
||||
flags: TGenFlags) =
|
||||
# a nop for certain types
|
||||
let flags = if opc == opcAddr: flags+{gfAddrOf} else: flags
|
||||
if unneededIndirection(n.sons[0]):
|
||||
# consider:
|
||||
# proc foo(f: var ref int) =
|
||||
# f = new(int)
|
||||
# proc blah() =
|
||||
# var x: ref int
|
||||
# foo x
|
||||
#
|
||||
# The type of 'f' is 'var ref int' and of 'x' is 'ref int'. Hence for
|
||||
# nkAddr we must not use 'unneededIndirection', but for deref we use it.
|
||||
if opc != opcAddr and unneededIndirection(n.sons[0]):
|
||||
gen(c, n.sons[0], dest, flags)
|
||||
message(n.info, warnUser, "YES")
|
||||
else:
|
||||
let tmp = c.genx(n.sons[0], flags)
|
||||
if dest < 0: dest = c.getTemp(n.typ)
|
||||
gABC(c, n, opc, dest, tmp)
|
||||
c.freeTemp(tmp)
|
||||
message(n.info, warnUser, "NO")
|
||||
|
||||
proc whichAsgnOpc(n: PNode): TOpcode =
|
||||
case n.typ.skipTypes(abstractRange-{tyTypeDesc}).kind
|
||||
|
||||
19
tests/macros/tvarnimnode.nim
Normal file
19
tests/macros/tvarnimnode.nim
Normal file
@@ -0,0 +1,19 @@
|
||||
discard """
|
||||
output: 10
|
||||
"""
|
||||
|
||||
#bug #926
|
||||
|
||||
import macros
|
||||
|
||||
proc test(f: var PNimrodNode) {.compileTime.} =
|
||||
f = newNimNode(nnkStmtList)
|
||||
f.add newCall(newIdentNode("echo"), newLit(10))
|
||||
|
||||
macro blah(prc: stmt): stmt =
|
||||
result = prc
|
||||
|
||||
test(result)
|
||||
|
||||
proc test() {.blah.} =
|
||||
echo 5
|
||||
Reference in New Issue
Block a user