Fix type recursion check (#11144)

* fixes #3456
* add test #3456
This commit is contained in:
Arne Döring
2019-05-07 08:29:17 +02:00
committed by Andreas Rumpf
parent a6ba3116b2
commit 6f7f043c9b
2 changed files with 15 additions and 4 deletions

View File

@@ -1517,11 +1517,12 @@ proc typeMismatch*(conf: ConfigRef; info: TLineInfo, formal, actual: PType) =
localError(conf, info, msg)
proc isTupleRecursive(t: PType, cycleDetector: var IntSet): bool =
if t == nil: return
if t == nil:
return false
if cycleDetector.containsOrIncl(t.id):
return true
case t.kind:
of tyTuple:
if cycleDetector.containsOrIncl(t.id):
return true
var cycleDetectorCopy: IntSet
for i in 0..<t.len:
assign(cycleDetectorCopy, cycleDetector)
@@ -1530,7 +1531,7 @@ proc isTupleRecursive(t: PType, cycleDetector: var IntSet): bool =
of tyAlias, tyRef, tyPtr, tyGenericInst, tyVar, tyLent, tySink, tyArray, tyUncheckedArray, tySequence:
return isTupleRecursive(t.lastSon, cycleDetector)
else:
discard
return false
proc isTupleRecursive*(t: PType): bool =
var cycleDetector = initIntSet()

View File

@@ -0,0 +1,10 @@
discard """
errormsg: "illegal recursion in type 'Weird'"
"""
# issue #3456
import tables
type
Weird = ref seq[Weird]
var t = newTable[int, Weird]()