ref: bc999872d044b073d9f20bd2278c58ad7811453c
parent: 6094e25e786b8092cf097135a48250917fd6c234
author: Ori Bernstein <[email protected]>
date: Wed Mar 5 06:38:16 EST 2014
Actually install the impls into the table in advance.
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1331,6 +1331,8 @@
t = gettrait(curstab(), n->impl.traitname);
if (!t)
fatal(n->line, "No trait %s\n", namestr(n->impl.traitname));
+ n->impl.type = tf(st, n->impl.type);
+ putimpl(curstab(), n);
dcl = NULL;
proto = NULL;
@@ -1375,7 +1377,6 @@
n->line, namestr(proto->decl.name), tystr(type(st, proto)), namestr(name), tystr(ty));
lappend(&file->file.stmts, &file->file.nstmts, dcl);
}
- putimpl(curstab(), n);
}
static void inferdecl(Inferstate *st, Node *n)
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -255,8 +255,6 @@
Node *name;
Type *type;
Node *init;
- Node **impls;
- size_t nimpls;
/*
If we have a link to a trait, we should only look it up
when specializing, but we should not create a new decl
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -251,7 +251,7 @@
if (gettrait(st, n))
fatal(n->line, "Trait %s already defined", namestr(n));
if (gettype(st, n))
- fatal(n->line, "Trait %s already defined as type", namestr(n));
+ fatal(n->line, "Trait %s already defined as a type", namestr(n));
td = xalloc(sizeof(Tydefn));
td->line = n->line;
td->name = n;
@@ -262,7 +262,7 @@
void putimpl(Stab *st, Node *n)
{
if (hasimpl(st, n))
- fatal(n->line, "Trait %s already defined", namestr(n));
+ fatal(n->line, "Trait %s already implemented over %s", namestr(n->impl.traitname), tystr(n->impl.type));
if (st->name)
setns(n->impl.traitname, namestr(st->name));
htput(st->impl, n, n);