ref: d2672685e9a9e2fe291215f4ca749a29f4e895a1
parent: 24e5832913b266731b7b0cbe430587ee6e76f683
author: Ori Bernstein <[email protected]>
date: Mon Oct 21 15:24:08 EDT 2013
Improve error messages sligthly.
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1271,8 +1271,8 @@
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));
+ 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));
@@ -1310,9 +1310,10 @@
/* returns the final type for t, after all unifications
* and default constraint selections */
-static Type *tyfix(Inferstate *st, Node *ctx, Type *t)
+static Type *tyfix(Inferstate *st, Node *ctx, Type *orig)
{
static Type *tyint, *tyflt;
+ Type *t, *delayed;
size_t i;
char buf[1024];
@@ -1321,9 +1322,15 @@
if (!tyflt)
tyflt = mktype(-1, Tyfloat64);
- t = tysearch(st, t);
- if (hthas(st->delayed, t))
- t = htget(st->delayed, t);
+ t = tysearch(st, orig);
+ printf("Orig: %s, t: %s\n", tystr(orig), tystr(t));
+ if (orig->type == Tyvar && hthas(st->delayed, orig)) {
+ delayed = htget(st->delayed, orig);
+ if (t->type == Tyvar)
+ t = delayed;
+ else if (tybase(t)->type != delayed->type)
+ fatal(ctx->line, "Type %s not compatible with %s near %s\n", tystr(t), tystr(delayed), ctxstr(st, ctx));
+ }
if (t->type == Tyvar) {
if (hascstr(t, cstrtab[Tcint]) && cstrcheck(t, tyint))
return tyint;