mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
error for NimNode index kind (#12154)
This commit is contained in:
committed by
Andreas Rumpf
parent
18135cc194
commit
e5139b0662
@@ -1384,17 +1384,21 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||
decodeBC(rkNode)
|
||||
let idx = regs[rc].intVal.int
|
||||
let src = regs[rb].node
|
||||
if src.kind notin {nkEmpty..nkNilLit} and idx <% src.len:
|
||||
regs[ra].node = src.sons[idx]
|
||||
else:
|
||||
if src.kind in {nkEmpty..nkNilLit}:
|
||||
stackTrace(c, tos, pc, "cannot get child of node kind: n" & $src.kind)
|
||||
elif idx >=% src.len:
|
||||
stackTrace(c, tos, pc, formatErrorIndexBound(idx, src.len-1))
|
||||
else:
|
||||
regs[ra].node = src.sons[idx]
|
||||
of opcNSetChild:
|
||||
decodeBC(rkNode)
|
||||
let idx = regs[rb].intVal.int
|
||||
var dest = regs[ra].node
|
||||
if nfSem in dest.flags and allowSemcheckedAstModification notin c.config.legacyFeatures:
|
||||
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))
|
||||
else:
|
||||
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:
|
||||
stackTrace(c, tos, pc, "typechecked nodes may not be modified")
|
||||
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:
|
||||
u.add(regs[rc].node)
|
||||
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:
|
||||
stackTrace(c, tos, pc, "typechecked nodes may not be modified")
|
||||
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:
|
||||
for i in 0 ..< x.len: u.add(x.sons[i])
|
||||
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")
|
||||
Reference in New Issue
Block a user