tlocals.nim 996 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. discard """
  2. output: '''(x: "string here", a: 1)
  3. b is 5
  4. x is 12'''
  5. """
  6. proc simple[T](a: T) =
  7. var
  8. x = "string here"
  9. echo locals()
  10. simple(1)
  11. type Foo2[T]=object
  12. a2: T
  13. proc numFields*(T: typedesc[tuple|object]): int=
  14. var t:T
  15. for _ in t.fields: inc result
  16. proc test(baz: int, qux: var int): int =
  17. var foo: Foo2[int]
  18. let bar = "abc"
  19. let c1 = locals()
  20. doAssert numFields(c1.foo.type) == 1
  21. doAssert c1.bar == "abc"
  22. doAssert c1.baz == 123
  23. doAssert c1.result == 0
  24. doAssert c1.qux == 456
  25. var x1 = 456
  26. discard test(123, x1)
  27. # bug #11958
  28. proc foo() =
  29. var a = 5
  30. proc bar() {.nimcall.} =
  31. var b = 5
  32. for k, v in fieldpairs(locals()):
  33. echo k, " is ", v
  34. bar()
  35. foo()
  36. proc foo2() =
  37. var a = 5
  38. proc bar2() {.nimcall.} =
  39. for k, v in fieldpairs(locals()):
  40. echo k, " is ", v
  41. bar2()
  42. foo2()
  43. proc foo3[T](y: T) =
  44. var a = 5
  45. proc bar2[T](x: T) {.nimcall.} =
  46. for k, v in fieldpairs(locals()):
  47. echo k, " is ", v
  48. bar2(y)
  49. foo3(12)