summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2017-06-10 22:03:35 +0300
committerAndreas Rumpf <rumpf_a@web.de>2017-06-20 11:29:42 +0200
commitba61e7e3ac0c2e1b323f97145645336e7f2e684c (patch)
treecc798bc44160c641927de52fc1ff29c02596b89b
parent9c6fe59b55db7abeafda9399ea20401eb1cd48e4 (diff)
downloadNim-ba61e7e3ac0c2e1b323f97145645336e7f2e684c.tar.gz
fix #2730; fix #4880
-rw-r--r--compiler/semtypinst.nim3
-rw-r--r--compiler/sigmatch.nim7
-rw-r--r--tests/statictypes/tpassthruarith.nim42
3 files changed, 51 insertions, 1 deletions
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim
index 2384934ee..b4a61deb7 100644
--- a/compiler/semtypinst.nim
+++ b/compiler/semtypinst.nim
@@ -127,7 +127,8 @@ proc replaceTypeVarsT*(cl: var TReplTypeVars, t: PType): PType =
 proc prepareNode(cl: var TReplTypeVars, n: PNode): PNode =
   let t = replaceTypeVarsT(cl, n.typ)
   if t != nil and t.kind == tyStatic and t.n != nil:
-    return t.n
+    return if tfUnresolved in t.flags: prepareNode(cl, t.n)
+           else: t.n
   result = copyNode(n)
   result.typ = t
   if result.kind == nkSym: result.sym = replaceTypeVarsS(cl, n.sym)
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index ff1ad9f0d..4a6ff3fce 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -1781,6 +1781,13 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
         arg.typ.sons = @[evaluated.typ]
         arg.typ.n = evaluated
         a = arg.typ
+      else:
+        if m.callee.kind == tyGenericBody:
+          if f.kind == tyStatic and typeRel(m, f.base, a) != isNone:
+            result = makeStaticExpr(m.c, arg)
+            result.typ.flags.incl tfUnresolved
+            result.typ.n = arg
+            return
 
   var r = typeRel(m, f, a)
 
diff --git a/tests/statictypes/tpassthruarith.nim b/tests/statictypes/tpassthruarith.nim
new file mode 100644
index 000000000..25cc46bad
--- /dev/null
+++ b/tests/statictypes/tpassthruarith.nim
@@ -0,0 +1,42 @@
+discard """
+output: '''
+[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
+
+[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
+
+[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
+
+[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
+'''
+"""
+
+# https://github.com/nim-lang/Nim/issues/4880
+
+proc `^^`(x: int): int = x * 2
+
+type
+  Foo[x: static[int]] = array[x, int]
+  Bar[a, b: static[int]] = array[b, Foo[^^a]]
+
+var x: Bar[2, 3]
+echo repr(x)
+
+# https://github.com/nim-lang/Nim/issues/2730
+
+type
+  Matrix[M,N: static[int]] = distinct array[0..(M*N - 1), int]
+
+proc bigger[M,N](m: Matrix[M,N]): Matrix[(M * N) div 8, (M * N)] =
+  discard
+
+proc bigger2[M,N](m: Matrix[M,N]): Matrix[M * 2, N * 2] =
+  discard
+
+var m : Matrix[4, 4]
+var n = bigger(m)
+var o = bigger2(m)
+
+echo repr(m)
+echo repr(n)
+echo repr(o)
+