From 64ffa17f0fac789f259d3db48a28f1605805a366 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Arne=20D=C3=B6ring?= <arne.doering@gmx.net>
Date: Sun, 22 Mar 2020 20:01:01 +0100
Subject: [PATCH] fixes #13715 (#13716)

* fixes #13715

* fix test
---
 compiler/types.nim                   | 5 ++++-
 tests/errmsgs/t8434.nim              | 2 +-
 tests/types/tillegalseqrecursion.nim | 6 ++++++
 3 files changed, 11 insertions(+), 2 deletions(-)
 create mode 100644 tests/types/tillegalseqrecursion.nim

diff --git a/compiler/types.nim b/compiler/types.nim
index 6b596b22ef7f6..33c81f9ccdf82 100644
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -593,7 +593,10 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
     of tyUncheckedArray:
       result = "UncheckedArray[" & typeToString(t[0]) & ']'
     of tySequence:
-      result = "seq[" & typeToString(t[0]) & ']'
+      if t.sym != nil and prefer != preferResolved:
+        result = t.sym.name.s
+      else:
+        result = "seq[" & typeToString(t[0]) & ']'
     of tyOpt:
       result = "opt[" & typeToString(t[0]) & ']'
     of tyOrdinal:
diff --git a/tests/errmsgs/t8434.nim b/tests/errmsgs/t8434.nim
index c8bc1193bcc9e..5d962ee5c9085 100644
--- a/tests/errmsgs/t8434.nim
+++ b/tests/errmsgs/t8434.nim
@@ -3,7 +3,7 @@ discard """
   nimout: '''but expected one of:
 proc fun0[T1: int | float | object | array | seq](a1: T1; a2: int)
   first type mismatch at position: 1
-  required type for a1: T1: int or float or object or array or seq[T]
+  required type for a1: T1: int or float or object or array or seq
   but expression 'byte(1)' is of type: byte
 
 expression: fun0(byte(1), 0)
diff --git a/tests/types/tillegalseqrecursion.nim b/tests/types/tillegalseqrecursion.nim
new file mode 100644
index 0000000000000..9221bb38a2742
--- /dev/null
+++ b/tests/types/tillegalseqrecursion.nim
@@ -0,0 +1,6 @@
+discard """
+  errormsg: "illegal recursion in type 'CyclicSeq'"
+"""
+# issue #13715
+type
+  CyclicSeq = seq[ref CyclicSeq]