ref: 033c515dda93159968574d4d0a1f32353a2b7750
parent: 29dbba4f6f70ab511fa4884b82dc1c0bbce3f981
author: Ori Bernstein <[email protected]>
date: Mon Jun 4 17:50:25 EDT 2012
Allow arrays to be unfied with the index hack.
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -169,6 +169,23 @@
}
}
+int idxhacked(Type **pa, Type **pb)
+{
+ Type *a, *b;
+
+ a = *pa;
+ b = *pb;
+ /* we want to unify Tyidxhack => concrete indexable. Flip
+ * to make this happen, if needed */
+ if (b->type == Tyidxhack) {
+ a = *pb;
+ b = *pa;
+ }
+ return a->type == Tyidxhack || a->type == Tyarray || a->type == Tyslice;
+}
+
+
+
static Type *unify(Node *ctx, Type *a, Type *b)
{
Type *t;
@@ -186,10 +203,9 @@
printf("UNIFY %s ===> %s\n", tystr(a), tystr(b));
mergecstrs(ctx, a, b);
if (a->type == Tyvar) {
- if (a->type == Tyvar)
- tytab[a->tid] = b;
- return b;
- } else if (a->type == b->type) {
+ tytab[a->tid] = b;
+ return b;
+ } else if (a->type == b->type || idxhacked(&a, &b)) {
for (i = 0; i < b->nsub; i++) {
/* types must have same arity */
if (i >= a->nsub)