ref: 73e2c5b1664a814e363364921270ae365473e622
parent: 6e4bf0cdecce71d9a839c1e7f6a42409c2f9d961
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Aug 20 15:52:05 EDT 2017
Fix a few bugs.
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -255,8 +255,6 @@
tr = traittab[Tcdisp];
ty = decltype(n);
- //if (!ty->traits || !bshas(ty->traits, Tcdisp))
- // return;
assert(tr->nproto == 1);
if (hthas(tr->proto[0]->decl.impls, ty))
return;
@@ -2603,6 +2601,18 @@
popstab();
}
}
+
+static Traitmap *
+mktraitmap()
+{
+ Traitmap *m;
+
+ m = zalloc(sizeof(Traitmap));
+ m->traits = mkbs();
+ m->name = mkht(namehash, nameeq);
+ return m;
+}
+
static void
builtintraits(void)
{
@@ -2609,11 +2619,8 @@
size_t i;
/* char::(numeric,integral) */
- for (i = 0; i < Ntypes; i++) {
- traitmap->sub[i] = zalloc(sizeof(Traitmap));
- traitmap->sub[i]->traits = mkbs();
- traitmap->sub[i]->name = mkht(namehash, nameeq);
- }
+ for (i = 0; i < Ntypes; i++)
+ traitmap->sub[i] = mktraitmap();
bsput(traitmap->sub[Tychar]->traits, Tcnum);
bsput(traitmap->sub[Tychar]->traits, Tcint);
@@ -2680,18 +2687,23 @@
{
Bitset *bs;
Traitmap *mm;
+ size_t i;
- if (!m->sub[ty->type]) {
- m->sub[ty->type] = zalloc(sizeof(Traitmap));
- m->sub[ty->type]->traits = mkbs();
- m->sub[ty->type]->name = mkht(namehash, nameeq);
- }
+ if (!m->sub[ty->type])
+ m = mktraitmap();
mm = m->sub[ty->type];
switch (ty->type) {
case Tygeneric:
case Typaram:
- lappend(&mm->filter, &m->nfilter, ty);
- lappend(&mm->filtertr, &m->nfiltertr, tr);
+ for (i = 0; i < Ntypes; i++) {
+ if (i == Typaram)
+ continue;
+ if (!m->sub[i])
+ m->sub[i] = mktraitmap();
+ mm = m->sub[i];
+ lappend(&mm->filter, &mm->nfilter, ty);
+ lappend(&mm->filtertr, &mm->nfiltertr, tr);
+ }
break;
case Tyname:
if (ty->ngparam == 0) {
--- a/parse/use.c
+++ b/parse/use.c
@@ -840,8 +840,11 @@
}
if (traitfix[i].dest)
*traitfix[i].dest = tr;
- if (traitfix[i].type)
+ if (traitfix[i].type && traitfix[i].type->type == Typaram) {
+ if (!traitfix[i].type->trneed)
+ traitfix[i].type->trneed = mkbs();
bsput(traitfix[i].type->trneed, tr->uid);
+ }
}
free(traitfix);