summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-07-01 18:08:50 +0200
committerGitHub <noreply@github.com>2019-07-01 18:08:50 +0200
commit766960dc15ad29a4d45a71ce24136bea0eba2268 (patch)
tree724b208c4a2613557e5ac84add9aabc63a4654c4
parent9b949855c7071749a459809f12da21d827eedc9d (diff)
downloadNim-766960dc15ad29a4d45a71ce24136bea0eba2268.tar.gz
fixes #11515 (#11624)
* fixes #11515

* better fix for #11515; make tests green
-rw-r--r--compiler/semexprs.nim7
-rw-r--r--compiler/seminst.nim2
-rw-r--r--tests/errmsgs/tnested_generic_instantiation.nim3
-rw-r--r--tests/errmsgs/tnested_generic_instantiation2.nim2
4 files changed, 8 insertions, 6 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index d52c87e7c..3e077f732 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -2023,8 +2023,11 @@ proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
   let oldErrorCount = c.config.errorCounter
   let oldErrorMax = c.config.errorMax
   let oldCompilesId = c.compilesContextId
-  inc c.compilesContextIdGenerator
-  c.compilesContextId = c.compilesContextIdGenerator
+  # if this is a nested 'when compiles', do not increase the ID so that
+  # generic instantations can still be cached for this level.
+  if c.compilesContextId == 0:
+    inc c.compilesContextIdGenerator
+    c.compilesContextId = c.compilesContextIdGenerator
   # do not halt after first error:
   c.config.errorMax = high(int)
 
diff --git a/compiler/seminst.nim b/compiler/seminst.nim
index d8abeb57f..43aa08818 100644
--- a/compiler/seminst.nim
+++ b/compiler/seminst.nim
@@ -98,7 +98,7 @@ proc sameInstantiation(a, b: TInstantiation): bool =
 proc genericCacheGet(genericSym: PSym, entry: TInstantiation;
                      id: CompilesId): PSym =
   for inst in genericSym.procInstCache:
-    if inst.compilesId == id and sameInstantiation(entry, inst[]):
+    if (inst.compilesId == 0 or inst.compilesId == id) and sameInstantiation(entry, inst[]):
       return inst.sym
 
 when false:
diff --git a/tests/errmsgs/tnested_generic_instantiation.nim b/tests/errmsgs/tnested_generic_instantiation.nim
index 77353605c..ab9ab54cd 100644
--- a/tests/errmsgs/tnested_generic_instantiation.nim
+++ b/tests/errmsgs/tnested_generic_instantiation.nim
@@ -1,6 +1,5 @@
 discard """
-errormsg: "generic instantiation too nested"
-file: "system.nim"
+action: compile
 """
 
 # bug #4766
diff --git a/tests/errmsgs/tnested_generic_instantiation2.nim b/tests/errmsgs/tnested_generic_instantiation2.nim
index d9bba15b0..c2ec31af8 100644
--- a/tests/errmsgs/tnested_generic_instantiation2.nim
+++ b/tests/errmsgs/tnested_generic_instantiation2.nim
@@ -1,5 +1,5 @@
 discard """
-errormsg: "generic instantiation too nested"
+action: compile
 """
 
 #[