fixes bug reported in PR #5637
This commit is contained in:
parent
560d87f5fd
commit
6cb8bf8045
3 changed files with 20 additions and 1 deletions
|
|
@ -1387,6 +1387,14 @@ 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 skipTypes*(t: PType, kinds: TTypeKinds; maxIters: int): PType =
|
||||||
|
result = t
|
||||||
|
var i = maxIters
|
||||||
|
while result.kind in kinds:
|
||||||
|
result = lastSon(result)
|
||||||
|
dec i
|
||||||
|
if i == 0: return nil
|
||||||
|
|
||||||
proc skipTypesOrNil*(t: PType, kinds: TTypeKinds): PType =
|
proc skipTypesOrNil*(t: PType, kinds: TTypeKinds): PType =
|
||||||
## same as skipTypes but handles 'nil'
|
## same as skipTypes but handles 'nil'
|
||||||
result = t
|
result = t
|
||||||
|
|
|
||||||
|
|
@ -1167,7 +1167,10 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
|
||||||
|
|
||||||
# special check for generic object with
|
# special check for generic object with
|
||||||
# generic/partial specialized parent
|
# generic/partial specialized parent
|
||||||
let tx = result.skipTypes(abstractPtrs)
|
let tx = result.skipTypes(abstractPtrs, 50)
|
||||||
|
if tx.isNil:
|
||||||
|
localError(n.info, "invalid recursion in type '$1'" % typeToString(result[0]))
|
||||||
|
return errorType(c)
|
||||||
if tx != result and tx.kind == tyObject and tx.sons[0] != nil:
|
if tx != result and tx.kind == tyObject and tx.sons[0] != nil:
|
||||||
semObjectTypeForInheritedGenericInst(c, n, tx)
|
semObjectTypeForInheritedGenericInst(c, n, tx)
|
||||||
|
|
||||||
|
|
|
||||||
8
tests/types/tillegaltyperecursion2.nim
Normal file
8
tests/types/tillegaltyperecursion2.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "invalid recursion in type 'Executor'"
|
||||||
|
line: 8
|
||||||
|
"""
|
||||||
|
# bug reported by PR #5637
|
||||||
|
type
|
||||||
|
Executor[N] = Executor[N]
|
||||||
|
var e: Executor[int]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue