summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorLemonBoy <LemonBoy@users.noreply.github.com>2019-02-10 22:07:51 +0100
committerAndreas Rumpf <rumpf_a@web.de>2019-02-13 23:30:14 +0100
commit0ebef1764d21dbd7ad05af0b3d00c78b0628f4fa (patch)
tree1220c0660a0a34fa4ae0ef562dfc0a7e01a0f2dd
parent942495611b266bc81dc4374e914fa990f3c2d6a2 (diff)
downloadNim-0ebef1764d21dbd7ad05af0b3d00c78b0628f4fa.tar.gz
Propagate tfGcSafe flag to generic instantiations (#10620)
Fixes a nasty endless loop in the generic instantiation phase.
-rw-r--r--compiler/semtypinst.nim5
-rw-r--r--tests/generics/tgenerics_various.nim11
2 files changed, 13 insertions, 3 deletions
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim
index ebe822cdf..ceabd8e60 100644
--- a/compiler/semtypinst.nim
+++ b/compiler/semtypinst.nim
@@ -300,7 +300,6 @@ proc instCopyType*(cl: var TReplTypeVars, t: PType): PType =
 proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
   # tyGenericInvocation[A, tyGenericInvocation[A, B]]
   # is difficult to handle:
-  const eqFlags = eqTypeFlags + {tfGcSafe}
   var body = t.sons[0]
   if body.kind != tyGenericBody:
     internalError(cl.c.config, cl.info, "no generic body")
@@ -311,7 +310,7 @@ proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
   else:
     result = searchInstTypes(t)
 
-  if result != nil and eqFlags*result.flags == eqFlags*t.flags:
+  if result != nil and sameFlags(result, t):
     when defined(reportCacheHits):
       echo "Generic instantiation cached ", typeToString(result), " for ", typeToString(t)
     return
@@ -329,7 +328,7 @@ proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
   if header != t:
     # search again after first pass:
     result = searchInstTypes(header)
-    if result != nil and eqFlags*result.flags == eqFlags*t.flags:
+    if result != nil and sameFlags(result, t):
       when defined(reportCacheHits):
         echo "Generic instantiation cached ", typeToString(result), " for ",
           typeToString(t), " header ", typeToString(header)
diff --git a/tests/generics/tgenerics_various.nim b/tests/generics/tgenerics_various.nim
index 9e6186534..656bfa566 100644
--- a/tests/generics/tgenerics_various.nim
+++ b/tests/generics/tgenerics_various.nim
@@ -242,3 +242,14 @@ block tvarargs_vs_generics:
   withDirectType "string"
   withOpenArray "string"
   withVarargs "string"
+
+block:
+  type
+    Que[T] {.gcsafe.} = object
+      x: T
+
+  proc `=`[T](q: var Que[T]; x: Que[T]) =
+    discard
+
+  var x: Que[int]
+  doAssert(x.x == 0)