ref: f4c04dca98997d3161158b0f3aa755e53cc07c81
parent: d3ab6d19ae584c5b10d8d7391811f3f26880aa50
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Jun 21 18:33:00 EDT 2016
Don't accidentally duck type unions. std.option is not the same as any union with `Some x; `None.
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -843,7 +843,7 @@
for (i = 0; i < u->nmemb; i++) {
found = 0;
for (j = 0; j < v->nmemb; j++) {
- if (strcmp(namestr(u->udecls[i]->name), namestr(v->udecls[j]->name)) != 0)
+ if (!nameeq(u->udecls[i]->name, v->udecls[j]->name))
continue;
found = 1;
if (u->udecls[i]->etype == NULL && v->udecls[j]->etype == NULL)
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -406,6 +406,7 @@
if (old)
lfatal(old->loc, "`%s already defined on %s:%d", namestr(uc->name), fname(uc->loc),
lnum(uc->loc));
+ setns(uc->name, st->name);
htput(st->uc, uc->name, uc);
}
@@ -532,5 +533,10 @@
if (td->type && (td->type->type == Tyname || td->type->type == Tygeneric))
setns(td->type->name, name);
}
+ free(k);
+
+ k = htkeys(st->uc, &nk);
+ for (i = 0; i < nk; i++)
+ setns(k[i], name);
free(k);
}
--- a/parse/type.c
+++ b/parse/type.c
@@ -486,21 +486,30 @@
static int fmtunion(char *buf, size_t len, Bitset *visited, Type *t)
{
- size_t i;
- char *end, *p;
- char *name;
char subbuf[512];
+ char *name, *ns, *sep;
+ char *end, *p;
+ size_t i;
+ Node *n;
p = buf;
end = p + len;
p += bprintf(p, end - p, "union\n");
for (i = 0; i < t->nmemb; i++) {
- name = namestr(t->udecls[i]->name);
+ n = t->udecls[i]->name;
+ if (n->name.ns) {
+ sep = ".";
+ ns = n->name.ns;
+ } else {
+ sep = "";
+ ns = "";
+ }
+ name = n->name.name;
if (t->udecls[i]->etype) {
tybfmt(subbuf, sizeof subbuf, visited, t->udecls[i]->etype);
- p += bprintf(p, end - p, "\t`%s %s\n", name, subbuf);
+ p += bprintf(p, end - p, "\t`%s%s%s %s\n", ns, sep, name, subbuf);
} else {
- p += bprintf(p, end - p, "\t`%s\n", name);
+ p += bprintf(p, end - p, "\t`%s%s%s\n", ns, sep, name);
}
}
p += bprintf(p, end - p, ";;");