summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorArne Döring <arne.doering@gmx.net>2019-04-28 10:11:41 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-04-28 10:11:41 +0200
commita432aedb5457f113d2389bfd09fbb20fd6eafc9b (patch)
tree0092043e8763a304188480ab95f926ea04ecf4cc
parentda3b649539c856fb9126d28f4354bf0170b363ad (diff)
downloadNim-a432aedb5457f113d2389bfd09fbb20fd6eafc9b.tar.gz
Generic tuple recursion fix (#11115)
* fixes #1145
* unify error messages
-rw-r--r--compiler/semtypes.nim4
-rw-r--r--tests/types/tillegaltuplerecursiongeneric.nim2
-rw-r--r--tests/types/tillegaltuplerecursiongeneric2.nim9
-rw-r--r--tests/types/tillegaltyperecursion2.nim2
4 files changed, 13 insertions, 4 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index e24597956..d0c8c8520 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -1348,8 +1348,8 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
   # special check for generic object with
   # generic/partial specialized parent
   let tx = result.skipTypes(abstractPtrs, 50)
-  if tx.isNil:
-    localError(c.config, n.info, "invalid recursion in type '$1'" % typeToString(result[0]))
+  if tx.isNil or isTupleRecursive(tx):
+    localError(c.config, n.info, "illegal recursion in type '$1'" % typeToString(result[0]))
     return errorType(c)
   if tx != result and tx.kind == tyObject and tx.sons[0] != nil:
     semObjectTypeForInheritedGenericInst(c, n, tx)
diff --git a/tests/types/tillegaltuplerecursiongeneric.nim b/tests/types/tillegaltuplerecursiongeneric.nim
index e5191e4d7..da65d48eb 100644
--- a/tests/types/tillegaltuplerecursiongeneric.nim
+++ b/tests/types/tillegaltuplerecursiongeneric.nim
@@ -1,5 +1,5 @@
 discard """
-  errormsg: "illegal recursion in type 'RefTreeInt'"
+  errormsg: "illegal recursion in type 'RefTree'"
 """
 
 type
diff --git a/tests/types/tillegaltuplerecursiongeneric2.nim b/tests/types/tillegaltuplerecursiongeneric2.nim
new file mode 100644
index 000000000..36ebd63be
--- /dev/null
+++ b/tests/types/tillegaltuplerecursiongeneric2.nim
@@ -0,0 +1,9 @@
+discard """
+  errormsg: "illegal recursion in type 'TPearl'"
+"""
+
+type
+  TPearl[T] = tuple
+    next: TPearl[T]
+
+var x: TPearl[int]
diff --git a/tests/types/tillegaltyperecursion2.nim b/tests/types/tillegaltyperecursion2.nim
index b5ffdda72..c539a361d 100644
--- a/tests/types/tillegaltyperecursion2.nim
+++ b/tests/types/tillegaltyperecursion2.nim
@@ -1,5 +1,5 @@
 discard """
-  errormsg: "invalid recursion in type 'Executor'"
+  errormsg: "illegal recursion in type 'Executor'"
   line: 8
 """
 # bug reported by PR #5637