* follow #16009 VM supports cast nil to ptr * more testcase
This commit is contained in:
parent
50d035b789
commit
fec19c980e
2 changed files with 33 additions and 0 deletions
|
|
@ -901,6 +901,9 @@ proc genCastIntFloat(c: PCtx; n: PNode; dest: var TDest) =
|
|||
c.gABx(n, opcSetType, dest, c.genType(dst))
|
||||
c.gABC(n, opcCastIntToPtr, dest, tmp)
|
||||
c.freeTemp(tmp)
|
||||
elif src.kind == tyNil and dst.kind in PtrLikeKinds:
|
||||
if dest < 0: dest = c.getTemp(n[0].typ)
|
||||
genLit(c, n[1], dest)
|
||||
else:
|
||||
# todo: support cast from tyInt to tyRef
|
||||
globalError(c.config, n.info, "VM does not support 'cast' from " & $src.kind & " to " & $dst.kind)
|
||||
|
|
|
|||
30
tests/vm/tcastnil.nim
Normal file
30
tests/vm/tcastnil.nim
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
discard """
|
||||
nimout: '''nil
|
||||
nil
|
||||
nil
|
||||
nil
|
||||
nil
|
||||
'''
|
||||
"""
|
||||
|
||||
block:
|
||||
static:
|
||||
let a = cast[pointer](nil)
|
||||
echo a.repr
|
||||
|
||||
block:
|
||||
static:
|
||||
echo cast[ptr int](nil).repr
|
||||
|
||||
block:
|
||||
const str = cast[ptr int](nil)
|
||||
static:
|
||||
echo str.repr
|
||||
|
||||
block:
|
||||
static:
|
||||
echo cast[ptr int](nil).repr
|
||||
|
||||
block:
|
||||
static:
|
||||
echo cast[RootRef](nil).repr
|
||||
Loading…
Add table
Add a link
Reference in a new issue