summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2015-02-14 21:47:21 +0100
committerAraq <rumpf_a@web.de>2015-02-14 21:47:21 +0100
commit442dc30922c226b8e5f82630bc76fa877dce1536 (patch)
tree2acda75982e1f5b2c88e05edcba004b6dec713c9
parentece23d39bce679be75da10e0e6b6fcf1814dca49 (diff)
downloadNim-442dc30922c226b8e5f82630bc76fa877dce1536.tar.gz
fixes endless recursion with static type parameters
-rw-r--r--compiler/sigmatch.nim12
-rw-r--r--tests/metatype/tstaticvector.nim17
2 files changed, 27 insertions, 2 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 00802e69b..7fbf0f165 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -1016,9 +1016,17 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
         if result != isNone: put(c.bindings, f, aOrig)
       else:
         result = isNone
+    elif prev.kind == tyStatic:
+      if aOrig.kind == tyStatic:
+        result = typeRel(c, prev.lastSon, a)
+        if result != isNone and prev.n != nil:
+          if not exprStructuralEquivalent(prev.n, aOrig.n):
+            result = isNone
+      else: result = isNone
     else:
-      result = typeRel(c, prev, aOrig)
-      
+      # XXX endless recursion?
+      #result = typeRel(c, prev, aOrig)
+      result = isNone
   of tyTypeDesc:
     var prev = PType(idTableGet(c.bindings, f))
     if prev == nil:
diff --git a/tests/metatype/tstaticvector.nim b/tests/metatype/tstaticvector.nim
new file mode 100644
index 000000000..c9923f469
--- /dev/null
+++ b/tests/metatype/tstaticvector.nim
@@ -0,0 +1,17 @@
+
+type
+  RectArray*[R, C: static[int], T] = distinct array[R * C, T]
+   
+  StaticMatrix*[R, C: static[int], T] = object
+    elements*: RectArray[R, C, T]
+   
+  StaticVector*[N: static[int], T] = StaticMatrix[N, 1, T]
+ 
+proc foo*[N, T](a: StaticVector[N, T]): T = 0.T
+proc foobar*[N, T](a, b: StaticVector[N, T]): T = 0.T
+ 
+ 
+var a: StaticVector[3, int]
+ 
+echo foo(a) # OK
+echo foobar(a, a) # <--- hangs compiler