Skip to content
Permalink
Browse files

closes #10180; closes #11494; closes #11483

  • Loading branch information...
Araq committed Aug 22, 2019
1 parent 74206ee commit d6238342de465fd91e63342e4b22f8d71d94c498
Showing with 58 additions and 1 deletion.
  1. +1 −1 compiler/evaltempl.nim
  2. +44 −0 tests/template/tmore_regressions.nim
  3. +13 −0 tests/template/tredefinition.nim
@@ -54,7 +54,7 @@ proc evalTemplateAux(templ, actual: PNode, c: var TemplCtx, result: PNode) =
# internalAssert c.config, false
idTablePut(c.mapping, s, x)
if sfGenSym in s.flags and optNimV019 notin c.config.globalOptions:
result.add newIdentNode(getIdent(c.ic, x.name.s & ":nim" & $x.id),
result.add newIdentNode(getIdent(c.ic, x.name.s & "`gensym" & $x.id),
if c.instLines: actual.info else: templ.info)
else:
result.add newSymNode(x, if c.instLines: actual.info else: templ.info)
@@ -0,0 +1,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()

@@ -0,0 +1,13 @@
discard """
errormsg: "redefinition of 'a`gensym"
line: 9
"""
# bug #10180
proc f() =
template t() =
var a = 1
var a = 2
echo a
t()

f()

0 comments on commit d623834

Please sign in to comment.
You can’t perform that action at this time.