tconstarrayresem2.nim 720 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. discard """
  2. output: '''
  3. 1
  4. 2
  5. 3
  6. FooBar
  7. foo1
  8. foo2
  9. foo3
  10. seq[int]
  11. @[5, 6]
  12. '''
  13. """
  14. # issue #13252
  15. import macros
  16. type
  17. FooBar = object
  18. a: seq[int]
  19. macro genFoobar(fb: static FooBar): untyped =
  20. result = newStmtList()
  21. for b in fb.a:
  22. result.add(newCall(bindSym"echo", newLit b))
  23. proc foobar(fb: static FooBar) =
  24. genFoobar(fb)
  25. echo fb.type # added line, same error when wrapped in static:
  26. # Error: undeclared field: 'a'
  27. for b in fb.a:
  28. echo "foo" & $b
  29. proc main() =
  30. const a: seq[int] = @[1, 2, 3]
  31. const fb = Foobar(a: a)
  32. foobar(fb)
  33. main()
  34. # issue #14917
  35. proc passSeq2[T](a : static seq[T]) =
  36. echo a
  37. template passSeq1[T](a : static seq[T]) =
  38. echo type(a)
  39. passSeq2(a)
  40. passSeq1(@[5,6])