tmacrogetimpl.nim 688 B

1234567891011121314151617181920212223242526272829303132
  1. import macros
  2. # bug #5034
  3. macro copyImpl(srsProc: typed, toSym: untyped) =
  4. result = copyNimTree(getImplTransformed(srsProc))
  5. result[0] = ident $toSym.toStrLit()
  6. proc foo1(x: float, one: bool = true): float =
  7. if one:
  8. return 1'f
  9. result = x
  10. proc bar1(what: string): string =
  11. ## be a little more adversarial with `skResult`
  12. proc buzz: string =
  13. result = "lightyear"
  14. if what == "buzz":
  15. result = "buzz " & buzz()
  16. else:
  17. result = what
  18. return result
  19. copyImpl(foo1, foo2)
  20. doAssert foo1(1'f) == 1.0
  21. doAssert foo2(10.0, false) == 10.0
  22. doAssert foo2(10.0) == 1.0
  23. copyImpl(bar1, bar2)
  24. doAssert bar1("buzz") == "buzz lightyear"
  25. doAssert bar1("macros") == "macros"