ref: 3543d66fb1a4bb9ca794a8031fa86579df1f4fb0
parent: 3bbe4ce2093413924189d6e8f0851a03524cf445
author: Ori Bernstein <[email protected]>
date: Mon Oct 21 08:09:23 EDT 2013
Better error messages
--- a/6/simp.c
+++ b/6/simp.c
@@ -1012,7 +1012,7 @@
}
}
if (!uc)
- die("Couldn't find union constructor");
+ die("Couldn't find union constructor %s in %s", namestr(n->expr.args[0]), tystr(ty));
if (dst)
tmp = dst;
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -238,6 +238,7 @@
pkgitem : decl
{putdcl(file->file.exports, $1);
+ $1->decl.isglobl = 1;
if ($1->decl.init)
lappend(&file->file.stmts, &file->file.nstmts, $1);}
| tydef {puttype(file->file.exports, mkname($1.line, $1.name), $1.type);
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -623,6 +623,10 @@
if (occurs(a, b))
fatal(ctx->line, "Infinite type %s in %s near %s",
tystr(a), tystr(b), ctxstr(st, ctx));
+ if (a->type == Tyname && b->type == Tyname)
+ if (!nameeq(a->name, b->name))
+ fatal(ctx->line, "%s incompatible with %s near %s",
+ tystr(a), tystr(b), ctxstr(st, ctx));
/* if the tyrank of a is 0 (ie, a raw tyvar), just unify.
* Otherwise, match up subtypes. */
@@ -636,9 +640,6 @@
} else if (hasparam(a) && hasparam(b)) {
/* Only Tygeneric and Tyname should be able to unify. And they
* should have the same names for this to be true. */
- if (!nameeq(a->name, b->name))
- fatal(ctx->line, "%s incompatible with %s near %s",
- tystr(a), tystr(b), ctxstr(st, ctx));
if (a->narg != b->narg)
fatal(ctx->line, "%s has wrong parameter list for %s near %s",
tystr(a), tystr(b), ctxstr(st, ctx));
@@ -1271,8 +1272,6 @@
break;
case Nmatchstmt:
infernode(st, n->matchstmt.val, NULL, sawret);
- if (tybase(type(st, n->matchstmt.val))->type == Tyvoid)
- fatal(n->line, "Can't match against a void type near %s", ctxstr(st, n->matchstmt.val));
for (i = 0; i < n->matchstmt.nmatches; i++) {
infernode(st, n->matchstmt.matches[i], ret, sawret);
unify(st, n, type(st, n->matchstmt.val), type(st, n->matchstmt.matches[i]->match.pat));
@@ -1322,7 +1321,7 @@
tyflt = mktype(-1, Tyfloat64);
t = tysearch(st, t);
- if (hthas(st->delayed, t))
+ if (t->type == Tyvar && hthas(st->delayed, t))
t = htget(st->delayed, t);
if (t->type == Tyvar) {
if (hascstr(t, cstrtab[Tcint]) && cstrcheck(t, tyint))
@@ -1524,6 +1523,8 @@
break;
case Nmatchstmt:
typesub(st, n->matchstmt.val);
+ if (tybase(type(st, n->matchstmt.val))->type == Tyvoid)
+ fatal(n->line, "Can't match against a void type near %s", ctxstr(st, n->matchstmt.val));
for (i = 0; i < n->matchstmt.nmatches; i++) {
typesub(st, n->matchstmt.matches[i]);
}
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -242,6 +242,7 @@
char isconst;
char isgeneric;
char isextern;
+ Vis vis;
Node *name;
Type *type;
Node *init;
--- a/parse/use.c
+++ b/parse/use.c
@@ -800,6 +800,8 @@
nodetag(n->lit.fnval);
break;
case Ndecl:
+ if (n->decl.vis == Visintern && n->decl.isglobl)
+ n->decl.vis = Vishidden;
taghidden(n->decl.type);
/* generics export their body. */
if (n->decl.isgeneric)
@@ -845,6 +847,7 @@
k = htkeys(st->dcl, &n);
for (i = 0; i < n; i++) {
s = getdcl(st, k[i]);
+ s->decl.vis = Visexport;
nodetag(s);
}
}
@@ -859,19 +862,19 @@
*/
void writeuse(FILE *f, Node *file)
{
- Stab *st;
- void **k;
+ Stab *ex;//, *st;
+ //void **k;
Node *s;
- size_t i, n;
+ size_t i; //, n;
- st = file->file.exports;
+ ex = file->file.exports;
wrbyte(f, 'U');
- if (st->name)
- wrstr(f, namestr(st->name));
+ if (ex->name)
+ wrstr(f, namestr(ex->name));
else
wrstr(f, NULL);
- tagexports(st);
+ tagexports(ex);
for (i = 0; i < ntypes; i++) {
if (types[i]->vis == Visexport || types[i]->vis == Vishidden) {
wrbyte(f, 'T');
@@ -879,6 +882,8 @@
typickle(f, types[i]);
}
}
+ /*
+ st = file->file.globls;
k = htkeys(st->dcl, &n);
for (i = 0; i < n; i++) {
s = getdcl(st, k[i]);
@@ -889,4 +894,15 @@
wrsym(f, s);
}
free(k);
+ */
+ for (i = 0; i < ndecls; i++) {
+ s = decls[i];
+ if (s->decl.vis == Visintern)
+ continue;
+ if (s->decl.isgeneric)
+ wrbyte(f, 'G');
+ else
+ wrbyte(f, 'D');
+ wrsym(f, s);
+ }
}