Skip to content

result.add x is not void when result is a NimNode, returns itself #19150

Open
@shirleyquirk

Description

@shirleyquirk

getting the type of a templated block inside a macro is complicated by the fact that typeof(result.add x) is NimNode and not void

Example

import macros
macro foo():untyped =
  result = nnkStmtList.newNimNode
  var x = nnkDiscardStmt.newTree(newEmptyNode())
  let str = result.add x # compiles ???
  doAssert str == result # ???
  doAssert typeof(result.add x) is NimNode #<= how i found out and what i really care about
foo()

Current Output

asserts all succeed

Expected Output

shouldn't compile; both assertions should fail

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions