tlocals.nim 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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)
  50. block: # bug #12682
  51. template foo(): untyped =
  52. var c1 = locals()
  53. 1
  54. proc testAll()=
  55. doAssert foo() == 1
  56. let c2=locals()
  57. testAll()