Nim/tests/generics/tgenerictmpl.nim
Adam Strzelecki f838c1baa4 fixes #3498
Previously it was not possible to use template arguments in template body as
the symbols were not resolved correctly leading to Error: undeclared
identifier: 'XX', eg.:

   template defaultOf[T](t: T): expr = (var d: T; d)
   echo defaultOf(1) #<- invalid identifier, but should output 0
2015-10-30 12:05:02 +01:00

21 lines
314 B
Nim

discard """
output: '''0
123'''
"""
# bug #3498
template defaultOf[T](t: T): expr = (var d: T; d)
echo defaultOf(1) #<- excpected 0
# assignment using template
template tassign[T](x: var seq[T]) =
x = @[1, 2, 3]
var y: seq[int]
tassign(y) #<- x is expected = @[1, 2, 3]
tassign(y)
echo y[0], y[1], y[2]