summary refs log tree commit diff stats
path: root/tests/template/tmore_regressions.nim
blob: 8b4b5fa4c75e56b9d332758d0ea5e081bb7893b2 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
discard """
output: '''0

0.0'''
"""

# bug #11494
import macros

macro staticForEach(arr: untyped, body: untyped): untyped =
    result = newNimNode(nnkStmtList)

    arr.expectKind(nnkBracket)
    for n in arr:
        let b = copyNimTree(body)
        result.add quote do:
            block:
                type it {.inject.} = `n`
                `b`

template forEveryMatchingEntity*() =
    staticForEach([int, string, float]):
        var a: it
        echo a

forEveryMatchingEntity()


# bug #11483
proc main =
  template first(body) =
    template second: var int =
      var o: int
      var i  = addr(o)
      i[]

    body

  first:
    second = 5
    second = 6

main()