fix #5683
This commit is contained in:
parent
8de19a7f4c
commit
d578815963
3 changed files with 25 additions and 6 deletions
|
|
@ -234,6 +234,7 @@ proc lookupTypeVar(cl: var TReplTypeVars, t: PType): PType =
|
||||||
proc instCopyType*(cl: var TReplTypeVars, t: PType): PType =
|
proc instCopyType*(cl: var TReplTypeVars, t: PType): PType =
|
||||||
# XXX: relying on allowMetaTypes is a kludge
|
# XXX: relying on allowMetaTypes is a kludge
|
||||||
result = copyType(t, t.owner, cl.allowMetaTypes)
|
result = copyType(t, t.owner, cl.allowMetaTypes)
|
||||||
|
if cl.allowMetaTypes: return
|
||||||
result.flags.incl tfFromGeneric
|
result.flags.incl tfFromGeneric
|
||||||
if not (t.kind in tyMetaTypes or
|
if not (t.kind in tyMetaTypes or
|
||||||
(t.kind == tyStatic and t.n == nil)):
|
(t.kind == tyStatic and t.n == nil)):
|
||||||
|
|
|
||||||
|
|
@ -826,7 +826,7 @@ proc inferStaticsInRange(c: var TCandidate,
|
||||||
let upperBound = tryResolvingStaticExpr(c, inferred.n[1],
|
let upperBound = tryResolvingStaticExpr(c, inferred.n[1],
|
||||||
allowUnresolved = true)
|
allowUnresolved = true)
|
||||||
|
|
||||||
template doInferStatic(c: var TCandidate, e: PNode, r: BiggestInt) =
|
template doInferStatic(e: PNode, r: BiggestInt) =
|
||||||
var exp = e
|
var exp = e
|
||||||
var rhs = r
|
var rhs = r
|
||||||
var inferred = inferStaticParam(exp, rhs)
|
var inferred = inferStaticParam(exp, rhs)
|
||||||
|
|
@ -842,9 +842,9 @@ proc inferStaticsInRange(c: var TCandidate,
|
||||||
return isGeneric
|
return isGeneric
|
||||||
else:
|
else:
|
||||||
return isNone
|
return isNone
|
||||||
doInferStatic(c, upperBound, lengthOrd(concrete) + lowerBound.intVal - 1)
|
doInferStatic(upperBound, lengthOrd(concrete) + lowerBound.intVal - 1)
|
||||||
elif upperBound.kind == nkIntLit:
|
elif upperBound.kind == nkIntLit:
|
||||||
doInferStatic(c, lowerBound, upperBound.intVal + 1 - lengthOrd(concrete))
|
doInferStatic(lowerBound, upperBound.intVal + 1 - lengthOrd(concrete))
|
||||||
|
|
||||||
template subtypeCheck() =
|
template subtypeCheck() =
|
||||||
if result <= isSubrange and f.lastSon.skipTypes(abstractInst).kind in {tyRef, tyPtr, tyVar}:
|
if result <= isSubrange and f.lastSon.skipTypes(abstractInst).kind in {tyRef, tyPtr, tyVar}:
|
||||||
|
|
@ -1054,7 +1054,8 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
|
||||||
return inferStaticsInRange(c, fRange, a)
|
return inferStaticsInRange(c, fRange, a)
|
||||||
elif c.c.inTypeClass > 0 and aRange.rangeHasUnresolvedStatic:
|
elif c.c.inTypeClass > 0 and aRange.rangeHasUnresolvedStatic:
|
||||||
return inferStaticsInRange(c, aRange, f)
|
return inferStaticsInRange(c, aRange, f)
|
||||||
elif lengthOrd(fRange) != lengthOrd(a):
|
else:
|
||||||
|
if lengthOrd(fRange) != lengthOrd(aRange):
|
||||||
result = isNone
|
result = isNone
|
||||||
else: discard
|
else: discard
|
||||||
of tyOpenArray, tyVarargs:
|
of tyOpenArray, tyVarargs:
|
||||||
|
|
@ -1260,7 +1261,9 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
|
||||||
of tyGenericInvocation:
|
of tyGenericInvocation:
|
||||||
var x = a.skipGenericAlias
|
var x = a.skipGenericAlias
|
||||||
# XXX: This is very hacky. It should be moved back into liftTypeParam
|
# 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)
|
let inst = prepareMetatypeForSigmatch(c.c, c.bindings, c.call.info, f)
|
||||||
return typeRel(c, inst, a)
|
return typeRel(c, inst, a)
|
||||||
|
|
||||||
|
|
|
||||||
15
tests/generics/t5683.nim
Normal file
15
tests/generics/t5683.nim
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue