diff options
author | Ori Bernstein <ori@eigenstate.org> | 2018-01-31 21:29:37 -0800 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2018-01-31 21:29:37 -0800 |
commit | 7caf9ecc7c84de4868bd4e7afccab59d2aa0fc9b (patch) | |
tree | 245ba6f402311d76b2699d9a7fd0ed33b9fe701f | |
parent | b4e3c2bc15b3b8adb559b70247222e56be207177 (diff) | |
download | mc-7caf9ecc7c84de4868bd4e7afccab59d2aa0fc9b.tar.gz |
Check that if we default to int, all necessary traits are there.
-rw-r--r-- | parse/infer.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/parse/infer.c b/parse/infer.c index 1c4d39f..9d2ba7e 100644 --- a/parse/infer.c +++ b/parse/infer.c @@ -2175,15 +2175,22 @@ static Type * tyfix(Node *ctx, Type *orig, int noerr) { static Type *tyint, *tyflt; + static Bitset *intset, *fltset; Type *t, *d, *base; Tyenv *env; size_t i; char buf[1024]; - if (!tyint) + if (!tyint) { tyint = mktype(Zloc, Tyint); - if (!tyflt) + intset = mkbs(); + traitsfor(tyint, intset); + } + if (!tyflt) { tyflt = mktype(Zloc, Tyflt64); + fltset = mkbs(); + traitsfor(tyflt, fltset); + } t = tysearch(tf(orig)); env = t->env; @@ -2202,9 +2209,9 @@ tyfix(Node *ctx, Type *orig, int noerr) } } if (t->type == Tyvar && t->trneed) { - if (bshas(t->trneed, Tcint) && bshas(t->trneed, Tcnum)) + if (bsissubset(t->trneed, intset)) t = tyint; - else if (bshas(t->trneed, Tcflt) && bshas(t->trneed, Tcnum)) + else if (bsissubset(t->trneed, fltset)) t = tyflt; } else if (!t->fixed) { t->fixed = 1; @@ -2233,8 +2240,11 @@ tyfix(Node *ctx, Type *orig, int noerr) if (t->type == Tyvar && !noerr) fatal(ctx, "underconstrained type %s near %s", tyfmt(buf, 1024, t), ctxstr(ctx)); - if (base) - t->seqaux = tyfix(ctx, base, noerr); + if (base) { + if (base != orig) + base = tyfix(ctx, base, noerr); + t->seqaux = base; + } if (env) popenv(env); return t; |