summaryrefslogtreecommitdiff
path: root/parse
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-06-21 22:33:00 -0700
committerOri Bernstein <ori@eigenstate.org>2016-06-21 22:33:00 -0700
commitf4c04dca98997d3161158b0f3aa755e53cc07c81 (patch)
tree3f2317b00ec16ceb14eae38ec54d1ef979570d82 /parse
parentd3ab6d19ae584c5b10d8d7391811f3f26880aa50 (diff)
downloadmc-f4c04dca98997d3161158b0f3aa755e53cc07c81.tar.gz
Don't accidentally duck type unions.
std.option is not the same as any union with `Some x; `None.
Diffstat (limited to 'parse')
-rw-r--r--parse/infer.c2
-rw-r--r--parse/stab.c6
-rw-r--r--parse/type.c21
3 files changed, 22 insertions, 7 deletions
diff --git a/parse/infer.c b/parse/infer.c
index d8a4695..989ac30 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -843,7 +843,7 @@ static void unionunify(Inferstate *st, Node *ctx, Type *u, Type *v)
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)
diff --git a/parse/stab.c b/parse/stab.c
index 8d5aeca..e3fce6e 100644
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -406,6 +406,7 @@ void putucon(Stab *st, Ucon *uc)
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);
}
@@ -533,4 +534,9 @@ void updatens(Stab *st, char *name)
setns(td->type->name, name);
}
free(k);
+
+ k = htkeys(st->uc, &nk);
+ for (i = 0; i < nk; i++)
+ setns(k[i], name);
+ free(k);
}
diff --git a/parse/type.c b/parse/type.c
index df123d1..7b1adc5 100644
--- a/parse/type.c
+++ b/parse/type.c
@@ -486,21 +486,30 @@ static int fmtstruct(char *buf, size_t len, Bitset *visited, Type *t)
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, ";;");