summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semtypes.nim25
-rw-r--r--tests/vm/tstaticprintseq.nim48
2 files changed, 58 insertions, 15 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index dd73cf01a..299a3a9b9 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -602,15 +602,24 @@ proc semObjectNode(c: PContext, n: PNode, prev: PType): PType =
     incl(result.flags, tfFinal)
 
 proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) =
-  if kind == skMacro and param.typ.kind notin {tyTypeDesc, tyStatic}:
-    # within a macro, every param has the type PNimrodNode!
-    # and param.typ.kind in {tyTypeDesc, tyExpr, tyStmt}:
-    let nn = getSysSym"PNimrodNode"
-    var a = copySym(param)
-    a.typ = nn.typ
-    if sfGenSym notin a.flags: addDecl(c, a)
+  template addDecl(x) =
+    if sfGenSym notin x.flags: addDecl(c, x)
+
+  if kind == skMacro:
+    if param.typ.kind == tyTypeDesc:
+      addDecl(param)
+    elif param.typ.kind == tyStatic:
+      var a = copySym(param)
+      a.typ = param.typ.base
+      addDecl(a)
+    else:
+      # within a macro, every param has the type PNimrodNode!
+      let nn = getSysSym"PNimrodNode"
+      var a = copySym(param)
+      a.typ = nn.typ
+      addDecl(a)
   else:
-    if sfGenSym notin param.flags: addDecl(c, param)
+    addDecl(param)
 
 let typedescId = getIdent"typedesc"
 
diff --git a/tests/vm/tstaticprintseq.nim b/tests/vm/tstaticprintseq.nim
index 99a56d161..f7ed1e2bb 100644
--- a/tests/vm/tstaticprintseq.nim
+++ b/tests/vm/tstaticprintseq.nim
@@ -4,18 +4,52 @@ discard """
 3
 1
 2
+3
+1
+2
+3
+1
+2
 3'''
 """
 
-const s = @[1,2,3]
+when false:
+  const s = @[1,2,3]
+
+  macro foo: stmt =
+    for e in s:
+      echo e
 
-macro foo: stmt =
-  for e in s:
-    echo e
+  foo()
 
-foo()
+  static:
+    for e in s:
+      echo e
+
+  macro bar(x: static[seq[int]]): stmt =
+    for e in x:
+      echo e
+
+  bar s
+  bar(@[1, 2, 3])
+
+type
+  TData = tuple
+    letters: seq[string]
+    numbers: seq[int]
+
+const data: TData = (@["aa", "bb"], @[11, 22])
 
 static:
-  for e in s:
-    echo e
+  for x in data.letters:
+    echo x
+
+  var m = data
+  for x in m.letters:
+    echo x
+
+macro ff(d: static[TData]): stmt =
+  for x in d.letters:
+    echo x
 
+ff(data)