summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2018-08-28 11:16:37 +0200
committerAraq <rumpf_a@web.de>2018-08-28 15:41:55 +0200
commit9c3cba1c2285a9d0250ed26f12598770e4ed78f4 (patch)
tree30c755a76f26c1c73f028ca91eaad71123c838f4
parentdc5851e87373203f5c64b9f15872e2865ab85f3f (diff)
downloadNim-9c3cba1c2285a9d0250ed26f12598770e4ed78f4.tar.gz
fixes #4766
-rw-r--r--compiler/seminst.nim3
-rw-r--r--tests/errmsgs/tnested_generic_instantiation.nim19
2 files changed, 21 insertions, 1 deletions
diff --git a/compiler/seminst.nim b/compiler/seminst.nim
index f9d7c3754..4bf1e6ef2 100644
--- a/compiler/seminst.nim
+++ b/compiler/seminst.nim
@@ -326,7 +326,8 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
   # no need to instantiate generic templates/macros:
   internalAssert c.config, fn.kind notin {skMacro, skTemplate}
   # generates an instantiated proc
-  if c.instCounter > 1000: internalError(c.config, fn.ast.info, "nesting too deep")
+  if c.instCounter > 50:
+    globalError(c.config, info, "generic instantiation too nested")
   inc(c.instCounter)
   # careful! we copy the whole AST including the possibly nil body!
   var n = copyTree(fn.ast)
diff --git a/tests/errmsgs/tnested_generic_instantiation.nim b/tests/errmsgs/tnested_generic_instantiation.nim
new file mode 100644
index 000000000..6aea7cbcc
--- /dev/null
+++ b/tests/errmsgs/tnested_generic_instantiation.nim
@@ -0,0 +1,19 @@
+discard """
+errormsg: "generic instantiation too nested"
+file: "system.nim"
+"""
+
+# bug #4766
+
+type
+  Plain = ref object
+    discard
+
+  Wrapped[T] = object
+    value: T
+
+converter toWrapped[T](value: T): Wrapped[T] =
+  Wrapped[T](value: value)
+
+let result = Plain()
+discard $result