tlocals.nim 536 B

12345678910111213141516171819202122232425262728293031
  1. discard """
  2. output: '''(x: "string here", a: 1)'''
  3. """
  4. proc simple[T](a: T) =
  5. var
  6. x = "string here"
  7. echo locals()
  8. simple(1)
  9. type Foo2[T]=object
  10. a2: T
  11. proc numFields*(T: typedesc[tuple|object]): int=
  12. var t:T
  13. for _ in t.fields: inc result
  14. proc test(baz: int, qux: var int): int =
  15. var foo: Foo2[int]
  16. let bar = "abc"
  17. let c1 = locals()
  18. doAssert numFields(c1.foo.type) == 1
  19. doAssert c1.bar == "abc"
  20. doAssert c1.baz == 123
  21. doAssert c1.result == 0
  22. doAssert c1.qux == 456
  23. var x1 = 456
  24. discard test(123, x1)