ref: 705f2d8c1f2d2b9f68ea7ef30af3b43d69a64b6a
parent: e2d1fada5b927cfe25f879271f4c8172a07b102e
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Feb 21 10:17:20 EST 2015
Error out on mismatched indexable types. foo[3] and foo[:] should not be compatible while inferring.
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -690,7 +690,11 @@
/* Tells us if we have an index hack on the type */
static int idxhacked(Type *a, Type *b)
{
- return (a->type == Tyvar && a->nsub > 0) || a->type == Tyarray || a->type == Tyslice;
+ if (a->type == Tyvar && a->nsub > 0)
+ return 1;
+ if (a->type == Tyarray || a->type == Tyslice)
+ return a->type == b->type;
+ return 0;
}
/* prevents types that contain themselves in the unification;
@@ -1441,10 +1445,12 @@
}
}
if (!proto)
- fatal(n, "Declaration %s missing in %s, near %s\n",
+ fatal(n, "Declaration %s missing in %s, near %s",
namestr(dcl->decl.name), namestr(t->name), ctxstr(st, n));
/* infer and unify types */
+ if (isgeneric(n->impl.type))
+ fatal(n, "trait specialization requires concrete type, got %s", tystr(n->impl.type));
checktraits(t->param, n->impl.type);
ht = mkht(tyhash, tyeq);
htput(ht, t->param, n->impl.type);