shithub: mc

Download patch

ref: 781d516f7d1c081f2d90b9f94b30b3400f7abd5f
parent: 950ee74350cdb6b7ff170234fd9341f1b094d171
author: Ori Bernstein <[email protected]>
date: Thu Dec 19 12:02:40 EST 2013

Add fixes for generic types that need to be respecialized.

    If we specialize from a generic to a generic, (eg, instantiating
    a generic from within a generic), then we may need to respecialize.

    The code was not handling that, and was allowing type params to
    propagage down to the backend.

--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -21,11 +21,14 @@
 {
     size_t i;
 
-    if (t->type == Typaram)
+    if (t->type == Typaram || t->isgeneric)
         return 1;
     for (i = 0; i < t->nsub; i++)
         if (hasparams(t->sub[i]))
             return 1;
+    for (i = 0; i < t->narg; i++)
+        if (hasparams(t->arg[i]))
+            return 1;
     return 0;
 }
 
@@ -51,7 +54,7 @@
             htput(tsmap, t, ret);
             break;
         case Tyname:
-            if (!t->isgeneric) {
+            if (!hasparams(t)) {
                 ret = t;
             } else {
                 for (i = 0; i < t->nparam; i++) {
@@ -123,6 +126,8 @@
     size_t i;
 
     if (from->type == Typaram) {
+        if (debugopt['S'])
+            printf("mapping %s => %s\n", tystr(from), tystr(to));
         htput(tsmap, from, to);
         return;
     }
@@ -383,6 +388,8 @@
 
     *name = genericname(n, to);
     d = getdcl(file->file.globls, *name);
+    if (debugopt['S'])
+        printf("specializing %s => %s\n", namestr(n->decl.name), namestr(*name));
     if (d)
         return d;
     /* namespaced names need to be looked up in their correct