summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semtempl.nim9
-rw-r--r--tests/template/tprocparshadow.nim11
2 files changed, 19 insertions, 1 deletions
diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim
index dfe3ded0d..e016e689c 100644
--- a/compiler/semtempl.nim
+++ b/compiler/semtempl.nim
@@ -263,9 +263,16 @@ proc semRoutineInTemplBody(c: var TemplCtx, n: PNode, k: TSymKind): PNode =
       n.sons[namePos] = ident
   else:
     n.sons[namePos] = semRoutineInTemplName(c, n.sons[namePos])
+  # open scope for parameters
   openScope(c)
-  for i in patternPos..bodyPos:
+  for i in patternPos..miscPos:
     n.sons[i] = semTemplBody(c, n.sons[i])
+  # open scope for locals
+  openScope(c)
+  n.sons[bodyPos] = semTemplBody(c, n.sons[bodyPos])
+  # close scope for locals
+  closeScope(c)
+  # close scope for parameters
   closeScope(c)
 
 proc semTemplSomeDecl(c: var TemplCtx, n: PNode, symKind: TSymKind; start=0) =
diff --git a/tests/template/tprocparshadow.nim b/tests/template/tprocparshadow.nim
new file mode 100644
index 000000000..b99cd0b6c
--- /dev/null
+++ b/tests/template/tprocparshadow.nim
@@ -0,0 +1,11 @@
+discard """
+  output: "10"
+"""
+
+template something(name: untyped) =
+  proc name(x: int) =
+    var x = x # this one should not be rejected by the compiler (#5225)
+    echo x
+
+something(what)
+what(10)