Size ptr tuple (#10846)

* fixes #10117
* Add support for recursive tuples
* detect in generics
This commit is contained in:
Arne Döring 2019-03-18 11:37:09 +01:00 • committed by Andreas Rumpf
commit 97c3b113a5
8 changed files with 153 additions and 10 deletions

View file

@ -1514,3 +1514,23 @@ proc typeMismatch*(conf: ConfigRef; info: TLineInfo, formal, actual: PType) =
of efLockLevelsDiffer:
msg.add "\nlock levels differ"
localError(conf, info, msg)
proc isTupleRecursive(t: PType, cycleDetector: var IntSet): bool =
if t == nil: return
case t.kind:
of tyTuple:
if cycleDetector.containsOrIncl(t.id):
return true
var cycleDetectorCopy: IntSet
for i in 0..<t.len:
assign(cycleDetectorCopy, cycleDetector)
if isTupleRecursive(t[i], cycleDetectorCopy):
return true
of tyAlias, tyRef, tyPtr, tyGenericInst, tyVar, tyLent, tySink, tyArray, tyUncheckedArray, tySequence:
return isTupleRecursive(t.lastSon, cycleDetector)
else:
discard
proc isTupleRecursive*(t: PType): bool =
var cycleDetector = initIntSet()
isTupleRecursive(t, cycleDetector)