From a432aedb5457f113d2389bfd09fbb20fd6eafc9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20D=C3=B6ring?= Date: Sun, 28 Apr 2019 10:11:41 +0200 Subject: [PATCH] Generic tuple recursion fix (#11115) * fixes #1145 * unify error messages --- compiler/semtypes.nim | 4 ++-- tests/types/tillegaltuplerecursiongeneric.nim | 2 +- tests/types/tillegaltuplerecursiongeneric2.nim | 9 +++++++++ tests/types/tillegaltyperecursion2.nim | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 tests/types/tillegaltuplerecursiongeneric2.nim diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index e245979567..d0c8c85203 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 e5191e4d74..da65d48eba 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 0000000000..36ebd63be9 --- /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 b5ffdda72b..c539a361d7 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