fixes #1691
This commit is contained in:
parent
c8dbeaa09b
commit
a1b937ab33
3 changed files with 24 additions and 7 deletions
|
|
@ -1317,6 +1317,13 @@ proc skipTypes*(t: PType, kinds: TTypeKinds): PType =
|
||||||
result = t
|
result = t
|
||||||
while result.kind in kinds: result = lastSon(result)
|
while result.kind in kinds: result = lastSon(result)
|
||||||
|
|
||||||
|
proc skipTypesOrNil*(t: PType, kinds: TTypeKinds): PType =
|
||||||
|
## same as skipTypes but handles 'nil'
|
||||||
|
result = t
|
||||||
|
while result != nil and result.kind in kinds:
|
||||||
|
if result.len == 0: return nil
|
||||||
|
result = lastSon(result)
|
||||||
|
|
||||||
proc isGCedMem*(t: PType): bool {.inline.} =
|
proc isGCedMem*(t: PType): bool {.inline.} =
|
||||||
result = t.kind in {tyString, tyRef, tySequence} or
|
result = t.kind in {tyString, tyRef, tySequence} or
|
||||||
t.kind == tyProc and t.callConv == ccClosure
|
t.kind == tyProc and t.callConv == ccClosure
|
||||||
|
|
|
||||||
|
|
@ -646,7 +646,10 @@ proc semObjectNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
# n.sons[0] contains the pragmas (if any). We process these later...
|
# n.sons[0] contains the pragmas (if any). We process these later...
|
||||||
checkSonsLen(n, 3)
|
checkSonsLen(n, 3)
|
||||||
if n.sons[1].kind != nkEmpty:
|
if n.sons[1].kind != nkEmpty:
|
||||||
base = skipTypes(semTypeNode(c, n.sons[1].sons[0], nil), skipPtrs)
|
base = skipTypesOrNil(semTypeNode(c, n.sons[1].sons[0], nil), skipPtrs)
|
||||||
|
if base.isNil:
|
||||||
|
localError(n.info, errIllegalRecursionInTypeX, "object")
|
||||||
|
else:
|
||||||
var concreteBase = skipGenericInvocation(base).skipTypes(skipPtrs)
|
var concreteBase = skipGenericInvocation(base).skipTypes(skipPtrs)
|
||||||
if concreteBase.kind == tyObject and tfFinal notin concreteBase.flags:
|
if concreteBase.kind == tyObject and tfFinal notin concreteBase.flags:
|
||||||
addInheritedFields(c, check, pos, concreteBase)
|
addInheritedFields(c, check, pos, concreteBase)
|
||||||
|
|
|
||||||
7
tests/objects/tillegal_recursion.nim
Normal file
7
tests/objects/tillegal_recursion.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "illegal recursion in type 'object'"
|
||||||
|
line: 7
|
||||||
|
"""
|
||||||
|
# bug #1691
|
||||||
|
type
|
||||||
|
Foo = ref object of Foo
|
||||||
Loading…
Add table
Add a link
Reference in a new issue