summaryrefslogtreecommitdiff
path: root/parse
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-02-21 15:17:20 -0800
committerOri Bernstein <ori@eigenstate.org>2015-02-21 15:17:20 -0800
commitc1241053700dac8c921f292f1e1b346ce1c1a966 (patch)
tree5dec92f1374d411bc5c82a4af65ace82152c4273 /parse
parentb3b586d20f2a1c4322f0679ee36d9b3431956e45 (diff)
downloadmc-c1241053700dac8c921f292f1e1b346ce1c1a966.tar.gz
Error out on mismatched indexable types.
foo[3] and foo[:] should not be compatible while inferring.
Diffstat (limited to 'parse')
-rw-r--r--parse/infer.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/parse/infer.c b/parse/infer.c
index 458b283..48896ae 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -690,7 +690,11 @@ static void mergetraits(Inferstate *st, Node *ctx, Type *a, Type *b)
/* 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 @@ static void specializeimpl(Inferstate *st, Node *n)
}
}
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);