summary refs log tree commit diff stats
path: root/tests/template/topensymoverride.nim
blob: 3d4bb59f14ad87440ad7caa7a5013c2b687abfa5 (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
discard """
  matrix: "--skipParentCfg --filenames:legacyRelProj"
"""

const value = "captured"
template fooOld(x: int, body: untyped): untyped =
  let value {.inject.} = "injected"
  body
template foo(x: int, body: untyped): untyped =
  let value {.inject.} = "injected"
  {.push experimental: "genericsOpenSym".}
  body
  {.pop.}

proc old[T](): string =
  fooOld(123):
    return value
doAssert old[int]() == "captured"

template oldTempl(): string =
  block:
    var res: string
    fooOld(123):
      res = value
    res
doAssert oldTempl() == "captured"

proc bar[T](): string =
  foo(123):
    return value
doAssert bar[int]() == "injected"

template barTempl(): string =
  block:
    var res: string
    foo(123):
      res = value
    res
doAssert barTempl() == "injected"