From 9c3cba1c2285a9d0250ed26f12598770e4ed78f4 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 28 Aug 2018 11:16:37 +0200 Subject: fixes #4766 --- compiler/seminst.nim | 3 ++- tests/errmsgs/tnested_generic_instantiation.nim | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/errmsgs/tnested_generic_instantiation.nim 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 -- cgit 1.4.1-2-gfad0