struct type *t = subst_apply_t(s0, fs[i]);
gamma_insert(gamma, decl[i]->ident, scheme_generalise(gamma, t));
+ for (int j = 0; i<decl[i]->natypes; j++) {
+ free(decl[i]->atypes[i]);
+ }
+ free(decl[i]->atypes);
decl[i]->atypes = safe_malloc(decl[i]->nargs*sizeof(struct type *));
decl[i]->natypes = decl[i]->nargs;
for (int j = 0; j<decl[i]->nargs; j++) {
if ((s = gamma_lookup(gamma, expr->data.efuncall.ident)) == NULL)
type_error(expr->loc, "Unbound function: %s\n"
, expr->data.efuncall.ident);
- struct type *t = scheme_instantiate(gamma, s);
-
+ struct type *ft = scheme_instantiate(gamma, s);
+ struct type *t = ft;
struct subst *s0 = subst_id();
//Infer args
for (int i = 0; i<expr->data.efuncall.nargs; i++) {
s1 = infer_expr(gamma,
expr->data.efuncall.args[i], t->data.tarrow.l);
s0 = subst_union(s1, s0);
- subst_apply_g(s0, gamma);
- t = subst_apply_t(s0, t->data.tarrow.r);
+ t = t->data.tarrow.r;
}
if (t->type == tarrow)
type_error(expr->loc, true,
//Infer return type
s1 = unify(expr->loc, t, type);
s0 = subst_union(s1, s0);
- type_free(t);
+ type_free(ft);
//TODO fields
return s0;
case eint:
struct subst *infer_stmt(struct gamma *gamma, struct stmt *stmt, struct type *type)
{
- struct subst *s0, *s1, *s2;
+ struct subst *s0, *s1;
struct type *f1;
switch (stmt->type) {
case sassign:
subst_insert(s, safe_strdup(sch->var[i]), gamma_fresh(gamma));
struct type *t = subst_apply_t(s, type_dup(sch->type));
- for (int i = 0; i<s->nvar; i++)
- free(s->vars[i]);
- free(s);
+ subst_free(s);
return t;
}