better fix for Issue #629 Recursive generic types not working
This commit is contained in:
parent
9df232911c
commit
4330c986db
1 changed files with 14 additions and 11 deletions
|
|
@ -808,11 +808,11 @@ proc SameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
||||||
if containsOrIncl(c, a, b): return true
|
if containsOrIncl(c, a, b): return true
|
||||||
|
|
||||||
proc sameFlags(a, b: PType): bool {.inline.} =
|
proc sameFlags(a, b: PType): bool {.inline.} =
|
||||||
result = eqTypeFlags*a.flags == eqTypeFlags*b.flags
|
result = eqTypeFlags*a.flags == eqTypeFlags*b.flags
|
||||||
|
|
||||||
if x == y: return true
|
if x == y: return true
|
||||||
var a = skipTypes(x, {tyGenericInst})
|
var a = skipTypes(x, {tyGenericInst})
|
||||||
var b = skipTypes(y, {tyGenericInst})
|
var b = skipTypes(y, {tyGenericInst})
|
||||||
assert(a != nil)
|
assert(a != nil)
|
||||||
assert(b != nil)
|
assert(b != nil)
|
||||||
if a.kind != b.kind:
|
if a.kind != b.kind:
|
||||||
|
|
@ -824,9 +824,7 @@ proc SameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
||||||
if a.kind != b.kind: return false
|
if a.kind != b.kind: return false
|
||||||
of dcEqOrDistinctOf:
|
of dcEqOrDistinctOf:
|
||||||
while a.kind == tyDistinct: a = a.sons[0]
|
while a.kind == tyDistinct: a = a.sons[0]
|
||||||
if a.kind != b.kind: return false
|
if a.kind != b.kind: return false
|
||||||
if x.Kind == tyGenericInst or y.Kind == tyGenericInst:
|
|
||||||
c.cmp = dcEqIgnoreDistinct
|
|
||||||
case a.Kind
|
case a.Kind
|
||||||
of tyEmpty, tyChar, tyBool, tyNil, tyPointer, tyString, tyCString,
|
of tyEmpty, tyChar, tyBool, tyNil, tyPointer, tyString, tyCString,
|
||||||
tyInt..tyBigNum, tyStmt:
|
tyInt..tyBigNum, tyStmt:
|
||||||
|
|
@ -839,15 +837,20 @@ proc SameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
||||||
result = sameObjectStructures(a, b, c) and sameFlags(a, b)
|
result = sameObjectStructures(a, b, c) and sameFlags(a, b)
|
||||||
of tyDistinct:
|
of tyDistinct:
|
||||||
CycleCheck()
|
CycleCheck()
|
||||||
if c.cmp == dcEq: result = sameTypeAux(a, b, c) and sameFlags(a, b)
|
if c.cmp == dcEq:
|
||||||
else: result = sameTypeAux(a.sons[0], b.sons[0], c) and sameFlags(a, b)
|
result = false
|
||||||
|
if a.sym != nil and b.sym != nil:
|
||||||
|
if a.sym.name == b.sym.name:
|
||||||
|
result = sameTypeAux(a.sons[0], b.sons[0], c) and sameFlags(a, b)
|
||||||
|
else:
|
||||||
|
result = sameTypeAux(a.sons[0], b.sons[0], c) and sameFlags(a, b)
|
||||||
of tyEnum, tyForward, tyProxy:
|
of tyEnum, tyForward, tyProxy:
|
||||||
# XXX generic enums do not make much sense, but require structural checking
|
# XXX generic enums do not make much sense, but require structural checking
|
||||||
result = a.id == b.id and sameFlags(a, b)
|
result = a.id == b.id and sameFlags(a, b)
|
||||||
of tyTuple:
|
of tyTuple:
|
||||||
CycleCheck()
|
CycleCheck()
|
||||||
result = sameTuple(a, b, c) and sameFlags(a, b)
|
result = sameTuple(a, b, c) and sameFlags(a, b)
|
||||||
of tyGenericInst:
|
of tyGenericInst:
|
||||||
result = sameTypeAux(lastSon(a), lastSon(b), c)
|
result = sameTypeAux(lastSon(a), lastSon(b), c)
|
||||||
of tyTypeDesc:
|
of tyTypeDesc:
|
||||||
if c.cmp == dcEqIgnoreDistinct: result = false
|
if c.cmp == dcEqIgnoreDistinct: result = false
|
||||||
|
|
@ -860,7 +863,7 @@ proc SameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
||||||
tyOpenArray, tySet, tyRef, tyPtr, tyVar, tyArrayConstr,
|
tyOpenArray, tySet, tyRef, tyPtr, tyVar, tyArrayConstr,
|
||||||
tyArray, tyProc, tyConst, tyMutable, tyVarargs, tyIter,
|
tyArray, tyProc, tyConst, tyMutable, tyVarargs, tyIter,
|
||||||
tyOrdinal, tyTypeClass:
|
tyOrdinal, tyTypeClass:
|
||||||
CycleCheck()
|
CycleCheck()
|
||||||
result = sameChildrenAux(a, b, c) and sameFlags(a, b)
|
result = sameChildrenAux(a, b, c) and sameFlags(a, b)
|
||||||
if result and (a.kind == tyProc):
|
if result and (a.kind == tyProc):
|
||||||
result = a.callConv == b.callConv
|
result = a.callConv == b.callConv
|
||||||
|
|
@ -869,7 +872,7 @@ proc SameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
||||||
result = SameTypeOrNilAux(a.sons[0], b.sons[0], c) and
|
result = SameTypeOrNilAux(a.sons[0], b.sons[0], c) and
|
||||||
SameValue(a.n.sons[0], b.n.sons[0]) and
|
SameValue(a.n.sons[0], b.n.sons[0]) and
|
||||||
SameValue(a.n.sons[1], b.n.sons[1])
|
SameValue(a.n.sons[1], b.n.sons[1])
|
||||||
of tyNone: result = false
|
of tyNone: result = false
|
||||||
|
|
||||||
proc sameType*(x, y: PType): bool =
|
proc sameType*(x, y: PType): bool =
|
||||||
var c = initSameTypeClosure()
|
var c = initSameTypeClosure()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue