Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shirleyquirk opened this issue Nov 15, 2021 · 3 comments
Open

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

shirleyquirk opened this issue Nov 15, 2021 · 3 comments
Labels

Comments

@shirleyquirk
Copy link
Contributor

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
@shirleyquirk
Copy link
Contributor Author

#14665

@shirleyquirk shirleyquirk changed the title result.add x is not void within macros, returns itself result.add x is not void when result is a NimNode, returns itself Nov 15, 2021
@Araq
Copy link
Member

Araq commented Nov 22, 2021

result.add should not return anything, this is a legacy that predates newTree. For 2.0 we should fix this.

@xigoi
Copy link

xigoi commented Jan 18, 2022

Maybe in the meantime, it could be useful to add {.discardable.} to prevent errors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants