tgensyminst.nim 642 B

123456789101112131415161718192021222324252627282930
  1. # issue #24048
  2. import macros
  3. proc map(fn: proc(val: int): void) = fn(1)
  4. # This works fine, and is the exact same function call as what's
  5. # generated by the macro `aBug`.
  6. map proc(val: auto): void =
  7. let variable = 123
  8. macro aBug() =
  9. # 1. let sym = ident("variable")
  10. let sym = genSym(nskLet, "variable")
  11. let letStmt = newLetStmt(sym, newLit(123))
  12. let lambda = newProc(
  13. params = @[
  14. ident("void"),
  15. newIdentDefs(ident("val"), ident("auto")),
  16. # 2. newIdentDefs(ident("val"), ident("int")),
  17. ],
  18. body = newStmtList(letStmt),
  19. procType = nnkLambda
  20. )
  21. result = newCall(bindSym("map"), lambda)
  22. aBug()