error for NimNode index kind (#12154)
This commit is contained in:
parent
18135cc194
commit
e5139b0662
4 changed files with 34 additions and 6 deletions
|
|
@ -1384,17 +1384,21 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
decodeBC(rkNode)
|
decodeBC(rkNode)
|
||||||
let idx = regs[rc].intVal.int
|
let idx = regs[rc].intVal.int
|
||||||
let src = regs[rb].node
|
let src = regs[rb].node
|
||||||
if src.kind notin {nkEmpty..nkNilLit} and idx <% src.len:
|
if src.kind in {nkEmpty..nkNilLit}:
|
||||||
regs[ra].node = src.sons[idx]
|
stackTrace(c, tos, pc, "cannot get child of node kind: n" & $src.kind)
|
||||||
else:
|
elif idx >=% src.len:
|
||||||
stackTrace(c, tos, pc, formatErrorIndexBound(idx, src.len-1))
|
stackTrace(c, tos, pc, formatErrorIndexBound(idx, src.len-1))
|
||||||
|
else:
|
||||||
|
regs[ra].node = src.sons[idx]
|
||||||
of opcNSetChild:
|
of opcNSetChild:
|
||||||
decodeBC(rkNode)
|
decodeBC(rkNode)
|
||||||
let idx = regs[rb].intVal.int
|
let idx = regs[rb].intVal.int
|
||||||
var dest = regs[ra].node
|
var dest = regs[ra].node
|
||||||
if nfSem in dest.flags and allowSemcheckedAstModification notin c.config.legacyFeatures:
|
if nfSem in dest.flags and allowSemcheckedAstModification notin c.config.legacyFeatures:
|
||||||
stackTrace(c, tos, pc, "typechecked nodes may not be modified")
|
stackTrace(c, tos, pc, "typechecked nodes may not be modified")
|
||||||
elif dest.kind in {nkEmpty..nkNilLit} or idx >=% dest.len:
|
elif dest.kind in {nkEmpty..nkNilLit}:
|
||||||
|
stackTrace(c, tos, pc, "cannot set child of node kind: n" & $dest.kind)
|
||||||
|
elif idx >=% dest.len:
|
||||||
stackTrace(c, tos, pc, formatErrorIndexBound(idx, dest.len-1))
|
stackTrace(c, tos, pc, formatErrorIndexBound(idx, dest.len-1))
|
||||||
else:
|
else:
|
||||||
dest.sons[idx] = regs[rc].node
|
dest.sons[idx] = regs[rc].node
|
||||||
|
|
@ -1404,7 +1408,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
if nfSem in u.flags and allowSemcheckedAstModification notin c.config.legacyFeatures:
|
if nfSem in u.flags and allowSemcheckedAstModification notin c.config.legacyFeatures:
|
||||||
stackTrace(c, tos, pc, "typechecked nodes may not be modified")
|
stackTrace(c, tos, pc, "typechecked nodes may not be modified")
|
||||||
elif u.kind in {nkEmpty..nkNilLit}:
|
elif u.kind in {nkEmpty..nkNilLit}:
|
||||||
stackTrace(c, tos, pc, "cannot add to node kind: " & $u.kind)
|
stackTrace(c, tos, pc, "cannot add to node kind: n" & $u.kind)
|
||||||
else:
|
else:
|
||||||
u.add(regs[rc].node)
|
u.add(regs[rc].node)
|
||||||
regs[ra].node = u
|
regs[ra].node = u
|
||||||
|
|
@ -1415,7 +1419,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
if nfSem in u.flags and allowSemcheckedAstModification notin c.config.legacyFeatures:
|
if nfSem in u.flags and allowSemcheckedAstModification notin c.config.legacyFeatures:
|
||||||
stackTrace(c, tos, pc, "typechecked nodes may not be modified")
|
stackTrace(c, tos, pc, "typechecked nodes may not be modified")
|
||||||
elif u.kind in {nkEmpty..nkNilLit}:
|
elif u.kind in {nkEmpty..nkNilLit}:
|
||||||
stackTrace(c, tos, pc, "cannot add to node kind: " & $u.kind)
|
stackTrace(c, tos, pc, "cannot add to node kind: n" & $u.kind)
|
||||||
else:
|
else:
|
||||||
for i in 0 ..< x.len: u.add(x.sons[i])
|
for i in 0 ..< x.len: u.add(x.sons[i])
|
||||||
regs[ra].node = u
|
regs[ra].node = u
|
||||||
|
|
|
||||||
8
tests/errmsgs/tnnodeadd.nim
Normal file
8
tests/errmsgs/tnnodeadd.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "cannot add to node kind: nnkInt8Lit"
|
||||||
|
line: 7
|
||||||
|
"""
|
||||||
|
import macros
|
||||||
|
macro t(x: untyped): untyped =
|
||||||
|
x.add(newEmptyNode())
|
||||||
|
t(38'i8)
|
||||||
8
tests/errmsgs/tnnodeindex.nim
Normal file
8
tests/errmsgs/tnnodeindex.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "index 5 not in 0 .. 2"
|
||||||
|
line: 7
|
||||||
|
"""
|
||||||
|
import macros
|
||||||
|
macro t(x: untyped): untyped =
|
||||||
|
result = x[5]
|
||||||
|
t([1, 2, 3])
|
||||||
8
tests/errmsgs/tnnodeindexkind.nim
Normal file
8
tests/errmsgs/tnnodeindexkind.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "cannot set child of node kind: nnkStrLit"
|
||||||
|
line: 7
|
||||||
|
"""
|
||||||
|
import macros
|
||||||
|
macro t(x: untyped): untyped =
|
||||||
|
x[0] = newEmptyNode()
|
||||||
|
t("abc")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue