summary refs log tree commit diff stats
path: root/compiler/evaltempl.nim
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2015-08-02 23:23:13 +0300
committerZahary Karadjov <zahary@gmail.com>2015-08-02 23:58:22 +0300
commitfe124ceadc887f0ae4aa09e9af4fe96b91df670a (patch)
treea2dd4469d0fb6ebe8f6ee8e5d4effe0a0da95124 /compiler/evaltempl.nim
parent02f97489b795cd33d49966e254b46fcc3f8072ba (diff)
downloadNim-fe124ceadc887f0ae4aa09e9af4fe96b91df670a.tar.gz
Disable the new generic params handling for immediate template and macros
Since immediate templates are not subjected to the standard sigmatching
algorithm, they will have a number of deficiencies when it comes to generic
params: Type dependencies between the parameters won't be honoured
and the bound generic symbols won't be resolvable within their bodies.
We could try to fix this, but it may be wiser to just deprecate immediate
templates and macros now that we have working untyped parameters.

Disabling the new features is admittedly not the greatest way to handle
this situations as it introduces inconsistency in the language, but at least
it makes the code backwards-compatible with the previous version of the
compiler instead of triggering more serious problems.
Diffstat (limited to 'compiler/evaltempl.nim')
-rw-r--r--compiler/evaltempl.nim12
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/evaltempl.nim b/compiler/evaltempl.nim
index 015c14ab5..82c4e8f57 100644
--- a/compiler/evaltempl.nim
+++ b/compiler/evaltempl.nim
@@ -66,7 +66,16 @@ proc evalTemplateArgs(n: PNode, s: PSym): PNode =
     else: 0
 
   var
-    genericParams = s.ast[genericParamsPos].len
+    # XXX: Since immediate templates are not subjected to the
+    # standard sigmatching algorithm, they will have a number
+    # of deficiencies when it comes to generic params:
+    # Type dependencies between the parameters won't be honoured
+    # and the bound generic symbols won't be resolvable within
+    # their bodies. We could try to fix this, but it may be
+    # wiser to just deprecate immediate templates and macros
+    # now that we have working untyped parameters.
+    genericParams = if sfImmediate in s.flags: 0
+                    else: s.ast[genericParamsPos].len
     expectedRegularParams = <s.typ.len
     givenRegularParams = totalParams - genericParams
 
@@ -81,6 +90,7 @@ proc evalTemplateArgs(n: PNode, s: PSym): PNode =
   # not supplied by the user
   for i in givenRegularParams+1 .. expectedRegularParams:
     let default = s.typ.n.sons[i].sym.ast
+    internalAssert default != nil
     if default.kind == nkEmpty:
       localError(n.info, errWrongNumberOfArguments)
       addSon(result, ast.emptyNode)