fix illegal recursion checks
This commit is contained in:
parent
a59f13b00d
commit
f34ca1a7d7
3 changed files with 18 additions and 18 deletions
|
|
@ -1144,8 +1144,10 @@ proc computeSizeAux(typ: PType, a: var biggestInt): biggestInt =
|
||||||
tyBigNum:
|
tyBigNum:
|
||||||
result = ptrSize
|
result = ptrSize
|
||||||
a = result
|
a = result
|
||||||
of tyArray, tyArrayConstr:
|
of tyArray, tyArrayConstr:
|
||||||
result = lengthOrd(typ.sons[0]) * computeSizeAux(typ.sons[1], a)
|
let elemSize = computeSizeAux(typ.sons[1], a)
|
||||||
|
if elemSize < 0: return elemSize
|
||||||
|
result = lengthOrd(typ.sons[0]) * elemSize
|
||||||
of tyEnum:
|
of tyEnum:
|
||||||
if firstOrd(typ) < 0:
|
if firstOrd(typ) < 0:
|
||||||
result = 4 # use signed int32
|
result = 4 # use signed int32
|
||||||
|
|
@ -1196,8 +1198,9 @@ proc computeSizeAux(typ: PType, a: var biggestInt): biggestInt =
|
||||||
of tyGenericInst, tyDistinct, tyGenericBody, tyMutable, tyConst, tyIter:
|
of tyGenericInst, tyDistinct, tyGenericBody, tyMutable, tyConst, tyIter:
|
||||||
result = computeSizeAux(lastSon(typ), a)
|
result = computeSizeAux(lastSon(typ), a)
|
||||||
of tyTypeDesc:
|
of tyTypeDesc:
|
||||||
result = (if typ.len == 1: computeSizeAux(typ.sons[0], a) else: -1)
|
result = if typ.len == 1: computeSizeAux(typ.sons[0], a)
|
||||||
of tyProxy: result = 1
|
else: szUnknownSize
|
||||||
|
of tyForward: return szIllegalRecursion
|
||||||
else:
|
else:
|
||||||
#internalError("computeSizeAux()")
|
#internalError("computeSizeAux()")
|
||||||
result = szUnknownSize
|
result = szUnknownSize
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,14 @@ discard """
|
||||||
line: 13
|
line: 13
|
||||||
errormsg: "illegal recursion in type \'TIllegal\'"
|
errormsg: "illegal recursion in type \'TIllegal\'"
|
||||||
"""
|
"""
|
||||||
# test illegal recursive types
|
# test illegal recursive types
|
||||||
|
|
||||||
type
|
|
||||||
TLegal {.final.} = object
|
|
||||||
x: int
|
|
||||||
kids: seq[TLegal]
|
|
||||||
|
|
||||||
TIllegal {.final.} = object #ERROR_MSG illegal recursion in type 'TIllegal'
|
|
||||||
y: Int
|
|
||||||
x: array[0..3, TIllegal]
|
|
||||||
|
|
||||||
|
type
|
||||||
|
TLegal {.final.} = object
|
||||||
|
x: int
|
||||||
|
kids: seq[TLegal]
|
||||||
|
|
||||||
|
TIllegal {.final.} = object #ERROR_MSG illegal recursion in type 'TIllegal'
|
||||||
|
y: Int
|
||||||
|
x: array[0..3, TIllegal]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ discard """
|
||||||
line: 7
|
line: 7
|
||||||
errormsg: "illegal recursion in type \'Uint8\'"
|
errormsg: "illegal recursion in type \'Uint8\'"
|
||||||
"""
|
"""
|
||||||
type
|
type
|
||||||
Uint8 = Uint8 #ERROR_MSG illegal recursion in type 'Uint8'
|
Uint8 = Uint8 #ERROR_MSG illegal recursion in type 'Uint8'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue