summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/astalgo.nim9
-rw-r--r--compiler/seminst.nim7
-rw-r--r--compiler/semtypes.nim3
-rw-r--r--tests/generics/tlateboundgenericparams.nim21
4 files changed, 37 insertions, 3 deletions
diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim
index 0afe56bb7..a4a14405e 100644
--- a/compiler/astalgo.nim
+++ b/compiler/astalgo.nim
@@ -31,6 +31,15 @@ when declared(echo):
   proc debug*(conf: ConfigRef; n: PType) {.deprecated.}
   proc debug*(conf: ConfigRef; n: PNode) {.deprecated.}
 
+  template debug*(x: PSym|PType|PNode) {.deprecated.} =
+    when compiles(c.config):
+      debug(c.config, x)
+    else:
+      error()
+
+  template debug*(x: auto) {.deprecated.} =
+    echo x
+
 template mdbg*: bool {.dirty.} =
   when compiles(c.module):
     c.module.fileIdx == c.config.projectMainIdx
diff --git a/compiler/seminst.nim b/compiler/seminst.nim
index 0047fd68e..0ad1fb872 100644
--- a/compiler/seminst.nim
+++ b/compiler/seminst.nim
@@ -248,8 +248,8 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
       resetIdTable(cl.symMap)
       resetIdTable(cl.localCache)
 
-    # take a note of the original type. If't a free type parameter
-    # we'll need to keep it unbount for the `fitNode` operation below...
+    # take a note of the original type. If't a free type or static parameter
+    # we'll need to keep it unbound for the `fitNode` operation below...
     var typeToFit = result[i]
 
     let needsStaticSkipping = result[i].kind == tyFromExpr
@@ -258,7 +258,8 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
       result[i] = result[i].skipTypes({tyStatic})
 
     # ...otherwise, we use the instantiated type in `fitNode`
-    if typeToFit.kind != tyTypeDesc or typeToFit.base.kind != tyNone:
+    if (typeToFit.kind != tyTypeDesc or typeToFit.base.kind != tyNone) and
+       (typeToFit.kind != tyStatic):
       typeToFit = result[i]
 
     internalAssert c.config, originalParams[i].kind == nkSym
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index f60b57d33..ff2820ec8 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -1056,6 +1056,9 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
         if not containsGenericType(typ):
           # check type compatibility between def.typ and typ:
           def = fitNode(c, typ, def, def.info)
+        elif typ.kind == tyStatic:
+          def = semConstExpr(c, def)
+          def = fitNode(c, typ, def, def.info)
 
     if not hasType and not hasDefault:
       if isType: localError(c.config, a.info, "':' expected")
diff --git a/tests/generics/tlateboundgenericparams.nim b/tests/generics/tlateboundgenericparams.nim
index 02f99dc55..9f0580fd2 100644
--- a/tests/generics/tlateboundgenericparams.nim
+++ b/tests/generics/tlateboundgenericparams.nim
@@ -1,3 +1,11 @@
+discard """
+  output: "1\n10\n1\n10"
+  nimout: '''
+bar instantiated with 1
+bar instantiated with 10
+'''
+"""
+
 import typetraits
 
 type
@@ -122,3 +130,16 @@ when true:
     var p = getOrigin[float]()
     var rotated = p.rotate(2.1)
 
+  test 7:
+    proc bar(x: static[int]) =
+      static: echo "bar instantiated with ", x
+      echo x
+
+    proc foo(x: static[int] = 1) =
+      bar(x)
+
+    foo()
+    foo(10)
+    foo(1)
+    foo(10)
+