tuntypedarg.nim 737 B

1234567891011121314151617181920
  1. import macros
  2. block: # issue #7385
  3. type CustomSeq[T] = object
  4. data: seq[T]
  5. macro `[]`[T](s: CustomSeq[T], args: varargs[untyped]): untyped =
  6. ## The end goal is to replace the joker "_" by something else
  7. result = newIntLitNode(10)
  8. proc foo1(): CustomSeq[int] =
  9. result.data.newSeq(10)
  10. # works since no overload matches first argument with type `CustomSeq`
  11. # except magic `[]`, which always matches without checking arguments
  12. doAssert result[_] == 10
  13. doAssert foo1() == CustomSeq[int](data: newSeq[int](10))
  14. proc foo2[T](): CustomSeq[T] =
  15. result.data.newSeq(10)
  16. # works fine with generic return type
  17. doAssert result[_] == 10
  18. doAssert foo2[int]() == CustomSeq[int](data: newSeq[int](10))