summary refs log tree commit diff stats
path: root/compiler/semtempl.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/semtempl.nim')
-rw-r--r--compiler/semtempl.nim16
1 files changed, 9 insertions, 7 deletions
diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim
index 74865ad58..8882e14f3 100644
--- a/compiler/semtempl.nim
+++ b/compiler/semtempl.nim
@@ -626,6 +626,8 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
   onDef(n[namePos].info, s)
   # check parameter list:
   #s.scope = c.currentScope
+  # push noalias flag at first to prevent unwanted recursive calls:
+  incl(s.flags, sfNoalias)
   pushOwner(c, s)
   openScope(c)
   n[namePos] = newSymNode(s)
@@ -635,7 +637,7 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
   setGenericParamsMisc(c, n)
   # process parameters:
   var allUntyped = true
-  var requiresParams = false
+  var nullary = true
   if n[paramsPos].kind != nkEmpty:
     semParamList(c, n[paramsPos], n[genericParamsPos], s)
     # a template's parameters are not gensym'ed even if that was originally the
@@ -648,7 +650,7 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
         param.flags.excl sfGenSym
       if param.typ.kind != tyUntyped: allUntyped = false
       # no default value, parameters required in call
-      if param.ast == nil: requiresParams = true
+      if param.ast == nil: nullary = false
   else:
     s.typ = newTypeS(tyProc, c)
     # XXX why do we need tyTyped as a return type again?
@@ -660,11 +662,11 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
     n[genericParamsPos] = n[miscPos][1]
     n[miscPos] = c.graph.emptyNode
   if allUntyped: incl(s.flags, sfAllUntyped)
-  if requiresParams or
-      n[bodyPos].kind == nkEmpty or
-      n[genericParamsPos].kind != nkEmpty:
-    # template cannot be called with alias syntax
-    incl(s.flags, sfNoalias)
+  if nullary and
+      n[genericParamsPos].kind == nkEmpty and
+      n[bodyPos].kind != nkEmpty:
+    # template can be called with alias syntax, remove pushed noalias flag
+    excl(s.flags, sfNoalias)
 
   if n[patternPos].kind != nkEmpty:
     n[patternPos] = semPattern(c, n[patternPos], s)