diff options
author | Arne Döring <arne.doering@gmx.net> | 2019-05-07 08:29:17 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-05-07 08:29:17 +0200 |
commit | 6f7f043c9b8c782f81568c330200d6ae8addee69 (patch) | |
tree | 5efadda18ab44aade5a0eb8cd8a7921863945236 | |
parent | a6ba3116b2376d9f3476ef0f8db5bbb32afc2a76 (diff) | |
download | Nim-6f7f043c9b8c782f81568c330200d6ae8addee69.tar.gz |
Fix type recursion check (#11144)
* fixes #3456 * add test #3456
-rw-r--r-- | compiler/types.nim | 9 | ||||
-rw-r--r-- | tests/types/tillegaltyperecursion3.nim | 10 |
2 files changed, 15 insertions, 4 deletions
diff --git a/compiler/types.nim b/compiler/types.nim index 199bd3352..a40a94421 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -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() diff --git a/tests/types/tillegaltyperecursion3.nim b/tests/types/tillegaltyperecursion3.nim new file mode 100644 index 000000000..8e1138329 --- /dev/null +++ b/tests/types/tillegaltyperecursion3.nim @@ -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]() |