fixes #23536; Stack trace with wrong line number when the proc called inside for loop (#23540)

fixes #23536
This commit is contained in:
ringabout
2024-04-26 22:02:02 +08:00
committed by GitHub
parent 407c0cb64a
commit 0b0f185bd1
2 changed files with 34 additions and 6 deletions

View File

@@ -456,6 +456,14 @@ proc transformYield(c: PTransf, n: PNode): PNode =
let rhs = transform(c, e)
result.add(asgnTo(lhs, rhs))
# bug #23536; note that the info of forLoopBody should't change
for idx in 0 ..< result.len:
var changeNode = result[idx]
changeNode.info = c.transCon.forStmt.info
for i, child in changeNode:
child.info = changeNode.info
inc(c.transCon.yieldStmts)
if c.transCon.yieldStmts <= 1:
# common case
@@ -466,12 +474,6 @@ proc transformYield(c: PTransf, n: PNode): PNode =
result.add(introduceNewLocalVars(c, c.transCon.forLoopBody))
c.isIntroducingNewLocalVars = false
for idx in 0 ..< result.len:
var changeNode = result[idx]
changeNode.info = c.transCon.forStmt.info
for i, child in changeNode:
child.info = changeNode.info
proc transformAddrDeref(c: PTransf, n: PNode, kinds: TNodeKinds): PNode =
result = transformSons(c, n)
# inlining of 'var openarray' iterators; bug #19977

26
tests/errmsgs/t23536.nim Normal file
View File

@@ -0,0 +1,26 @@
discard """
matrix: "--stackTrace:on --excessiveStackTrace:off"
"""
const expected = """
wrong trace:
t23536.nim(22) t23536
t23536.nim(17) foo
assertions.nim(41) failedAssertImpl
assertions.nim(36) raiseAssert
fatal.nim(53) sysFatal
"""
try:
proc foo = # bug #23536
doAssert false
for i in 0 .. 1:
foo()
except AssertionDefect:
let e = getCurrentException()
let trace = e.getStackTrace
doAssert "wrong trace:\n" & trace == expected