tlocals.nim 1.2 KB

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