summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semfold.nim4
-rw-r--r--compiler/semtypes.nim4
-rw-r--r--compiler/types.nim4
-rw-r--r--tests/compile/tvarious.nim12
4 files changed, 21 insertions, 3 deletions
diff --git a/compiler/semfold.nim b/compiler/semfold.nim
index 6fdb780c9..9c158b9ef 100644
--- a/compiler/semfold.nim
+++ b/compiler/semfold.nim
@@ -625,6 +625,10 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
           result = newIntNodeT(sonsLen(a), n)
         else:
           result = magicCall(m, n)
+      of mLengthArray:
+        # It doesn't matter if the argument is const or not for mLengthArray.
+        # This fixes bug #544.
+        result = newIntNodeT(lengthOrd(n.sons[1].typ), n)
       of mAstToStr:
         result = newStrNodeT(renderTree(n[1], {renderNoComments}), n)
       of mConStrStr:
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index 7efa207a8..47d600e16 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -841,7 +841,9 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
       LocalError(n.info, errTypeExpected)
       result = newOrPrevType(tyError, prev, c)
   of nkCallKinds:
-    if n[0].kind == nkIdent:
+    if isRange(n):
+      result = semRangeAux(c, n, prev)
+    elif n[0].kind == nkIdent:
       let op = n.sons[0].ident
       if op.id in {ord(wAnd), ord(wOr)} or op.s == "|":
         checkSonsLen(n, 3)
diff --git a/compiler/types.nim b/compiler/types.nim
index 3096b73c8..9dad958b8 100644
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -959,8 +959,8 @@ proc skipGenericAlias*(t: PType): PType =
 proc matchTypeClass*(bindings: var TIdTable, typeClass, t: PType): bool =
   for i in countup(0, typeClass.sonsLen - 1):
     let req = typeClass.sons[i]
-    var match = req.kind == skipTypes(t, {tyRange, tyGenericInst}).kind
-      
+    var match = req.kind == skipTypes(t, {tyGenericInst, tyRange}).kind or
+                req.kind == skipTypes(t, {tyGenericInst}).kind
     if not match:
       case req.kind
       of tyGenericBody:
diff --git a/tests/compile/tvarious.nim b/tests/compile/tvarious.nim
index e301b34f6..e91de9245 100644
--- a/tests/compile/tvarious.nim
+++ b/tests/compile/tvarious.nim
@@ -46,3 +46,15 @@ while i < s.len:
   i = i + 1

 

 write(stdout, "Du heißt " & s)

+
+# bug #544
+
+type Bar [T; I:range] = array[I, T]
+proc foo*[T; I:range](a, b: Bar[T, I]): Bar[T, I] =
+  when len(a) != 3: 
+    # Error: constant expression expected
+    {.fatal:"Dimensions have to be 3".}
+  #...
+block:
+  var a, b: Bar[int, 0..2]
+  discard foo(a, b)