Skip to content

ProcDef is not re-evaluated between typed macros which was added to the proc pragmas by an another typed macro #18349

@alaviss

Description

@alaviss

Example

import macros

macro foo(x: static[int], n: typed): untyped =
  result = n
  if result.kind in RoutineNodes:
    echo "foo on ", result.name, ", x: ", x
  else:
    echo "foo on ", result.kind, ", x: ", x

macro addFooToBody(x: static[int], n: typed): untyped =
  result = copyNimTree n
  result.body = newStmtList:
    newCall(bindSym"foo", newLit x):
      result.body
  echo "added foo(", x, ") to body"

macro addFoo(n: typed): untyped =
  result = copyNimTree n
  # This is also the wrong order to add the macros, see nim-lang/Nim#18348
  result.addPragma:
    nnkExprColonExpr.newTree(bindSym"addFooToBody", newLit 1)
  result.addPragma:
    nnkExprColonExpr.newTree(bindSym"foo", newLit 2)
 
proc test() {.used, addFoo.} =
  discard

Current Output

added foo(1) to body
foo on test, x: 2
foo on nnkDiscardStmt, x: 1

Expected Output

added foo(1) to body
foo on nnkDiscardStmt, x: 1
foo on test, x: 2

Additional Information

$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-06-24
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 0f91b67f5c15328330f74a8769aed9961940aab2
active boot switches: -d:release -d:nimUseLinenoise

Metadata

Metadata

Assignees

No one assigned

    Labels

    CPSbugs/pulls related to the cps projectMacros

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions