status-im/nim-chronos

Compilation error: `invalid pragma: stackTrace: false`

SirNickolas opened this issue · 2 comments

In some cases, when generating an .async procedure by a macro, you get the aforementioned error. Example:

import std/macros
import chronos/asyncloop

func recurse(tree: NimNode): NimNode =
  tree.expectKind {nnkProcDef, nnkIteratorDef, nnkStmtList}
  if tree.kind == nnkStmtList:
    for i, child in tree:
      tree[i] = child.recurse
    tree
  else:
    let name = tree[0]
    quote do:
      proc `name` {.async.} = discard

macro turnIntoProc(tree: untyped) =
  tree.recurse

proc test0 {.turnIntoProc.}
# OK

iterator test1 {.turnIntoProc.}
# Error: invalid pragma: stackTrace: false

turnIntoProc:
  iterator test2
# OK

(The last test confuses me the most, to be honest.) The error is caused by these lines:

if prc.kind notin {nnkProcTy, nnkLambda}: # TODO: Nim bug?
prc.addPragma(newColonExpr(ident "stackTrace", ident "off"))

Could you explain their meaning please?

Any ideas on how to make the example compileable are much appreciated. (Checking if tree is an nnkStmtList and, if not, rewriting to bindSym"turnIntoProc".newCall newStmtList tree doesn’t work. Even with tree.copyNimTree.)

Chronos 3.0.11, Nim 1.6.10.

this is a Nim bug that has been fixed in more recent versions, see nim-lang/Nim#22198

Thanks for reporting it. I’m afraid, there’s no much we can do with it then. I think I’ll just write in the Readme that it has been fixed in Nim 2.0.