From f2cdbc92eb2aead4b7ee4c8a9156e17edc2edd9c Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 25 Feb 2015 20:32:32 +0100 Subject: [PATCH] fixes #2215 --- compiler/seminst.nim | 21 +++++++++++---------- compiler/semtempl.nim | 2 +- tests/template/tparams_gensymed.nim | 29 +++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/compiler/seminst.nim b/compiler/seminst.nim index d745840963..a10f275193 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -80,13 +80,9 @@ proc freshGenSyms(n: PNode, owner: PSym, symMap: var TIdTable) = let s = n.sym var x = PSym(idTableGet(symMap, s)) if x == nil: - if s.kind == skParam: - x = owner.typ.n[s.position+1].sym - internalAssert x.kind == skParam - else: - x = copySym(s, false) - x.owner = owner - idTablePut(symMap, s, x) + x = copySym(s, false) + x.owner = owner + idTablePut(symMap, s, x) n.sym = x else: for i in 0 .. 0: diff --git a/tests/template/tparams_gensymed.nim b/tests/template/tparams_gensymed.nim index 33940874d7..6c4413866f 100644 --- a/tests/template/tparams_gensymed.nim +++ b/tests/template/tparams_gensymed.nim @@ -31,3 +31,32 @@ var x: Something testB(x) +# bug #2215 +# Test that templates in generics still work (regression to fix the +# regression...) + +template forStatic(index: expr, slice: Slice[int], predicate: stmt): + stmt {.immediate.} = + const a = slice.a + const b = slice.b + when a <= b: + template iteration(i: int) = + block: + const index = i + predicate + template iterateStartingFrom(i: int): stmt = + when i <= b: + iteration i + iterateStartingFrom i + 1 + iterateStartingFrom a + +proc concreteProc(x: int) = + forStatic i, 0..3: + echo i + +proc genericProc(x: any) = + forStatic i, 0..3: + echo i + +concreteProc(7) # This works +genericProc(7) # This doesn't compile