summary refs log tree commit diff stats
path: root/tests/misc/tlocals.nim
blob: e6c73313d147c0b8ed79587fb19c46f1add193be (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
discard """
  output: '''(x: "string here", a: 1)'''
"""

proc simple[T](a: T) =
  var
    x = "string here"
  echo locals()

simple(1)

type Foo2[T]=object
  a2: T

proc numFields*(T: typedesc[tuple|object]): int=
  var t:T
  for _ in t.fields: inc result

proc test(baz: int, qux: var int): int =
  var foo: Foo2[int]
  let bar = "abc"
  let c1 = locals()
  doAssert numFields(c1.foo.type) == 1
  doAssert c1.bar == "abc"
  doAssert c1.baz == 123
  doAssert c1.result == 0
  doAssert c1.qux == 456

var x1 = 456
discard test(123, x1)