diff options
author | Zahary Karadjov <zahary@gmail.com> | 2017-04-14 23:54:09 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2017-04-14 23:54:09 +0300 |
commit | d578815963ad603bc083ac0cf15b29ff9a6e4ed7 (patch) | |
tree | 4778fbd531191fccb0ca646996521eef601a9b96 | |
parent | 8de19a7f4c5387042994e061aa28545b090b3997 (diff) | |
download | Nim-d578815963ad603bc083ac0cf15b29ff9a6e4ed7.tar.gz |
fix #5683
-rw-r--r-- | compiler/semtypinst.nim | 1 | ||||
-rw-r--r-- | compiler/sigmatch.nim | 15 | ||||
-rw-r--r-- | tests/generics/t5683.nim | 15 |
3 files changed, 25 insertions, 6 deletions
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index d550a0c85..80fb9168b 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -234,6 +234,7 @@ proc lookupTypeVar(cl: var TReplTypeVars, t: PType): PType = proc instCopyType*(cl: var TReplTypeVars, t: PType): PType = # XXX: relying on allowMetaTypes is a kludge result = copyType(t, t.owner, cl.allowMetaTypes) + if cl.allowMetaTypes: return result.flags.incl tfFromGeneric if not (t.kind in tyMetaTypes or (t.kind == tyStatic and t.n == nil)): diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 89c885c64..43a939007 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -826,7 +826,7 @@ proc inferStaticsInRange(c: var TCandidate, let upperBound = tryResolvingStaticExpr(c, inferred.n[1], allowUnresolved = true) - template doInferStatic(c: var TCandidate, e: PNode, r: BiggestInt) = + template doInferStatic(e: PNode, r: BiggestInt) = var exp = e var rhs = r var inferred = inferStaticParam(exp, rhs) @@ -842,9 +842,9 @@ proc inferStaticsInRange(c: var TCandidate, return isGeneric else: return isNone - doInferStatic(c, upperBound, lengthOrd(concrete) + lowerBound.intVal - 1) + doInferStatic(upperBound, lengthOrd(concrete) + lowerBound.intVal - 1) elif upperBound.kind == nkIntLit: - doInferStatic(c, lowerBound, upperBound.intVal + 1 - lengthOrd(concrete)) + doInferStatic(lowerBound, upperBound.intVal + 1 - lengthOrd(concrete)) template subtypeCheck() = if result <= isSubrange and f.lastSon.skipTypes(abstractInst).kind in {tyRef, tyPtr, tyVar}: @@ -1054,8 +1054,9 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation = return inferStaticsInRange(c, fRange, a) elif c.c.inTypeClass > 0 and aRange.rangeHasUnresolvedStatic: return inferStaticsInRange(c, aRange, f) - elif lengthOrd(fRange) != lengthOrd(a): - result = isNone + else: + if lengthOrd(fRange) != lengthOrd(aRange): + result = isNone else: discard of tyOpenArray, tyVarargs: # varargs[expr] is special too but handled earlier. So we only need to @@ -1260,7 +1261,9 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation = of tyGenericInvocation: var x = a.skipGenericAlias # XXX: This is very hacky. It should be moved back into liftTypeParam - if x.kind == tyGenericInst and c.calleeSym != nil and c.calleeSym.kind == skProc: + if x.kind in {tyGenericInst, tyArray} and + c.calleeSym != nil and + c.calleeSym.kind == skProc: let inst = prepareMetatypeForSigmatch(c.c, c.bindings, c.call.info, f) return typeRel(c, inst, a) diff --git a/tests/generics/t5683.nim b/tests/generics/t5683.nim new file mode 100644 index 000000000..08ec7f30d --- /dev/null +++ b/tests/generics/t5683.nim @@ -0,0 +1,15 @@ +discard """ +output: "perm: 22 det: 22" +""" + +type Matrix[M,N: static[int]] = array[M, array[N, float]] + +proc det[M,N](a: Matrix[M,N]): int = N*10 + M +proc perm[M,N](a: Matrix[M,N]): int = M*10 + N + +const + a = [ [1.0, 2.0] + , [3.0, 4.0] + ] + +echo "perm: ", a.perm, " det: ", a.det |