summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2019-12-15 16:49:50 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2019-12-15 16:49:50 -0500
commit6324510cab2b76dbdaf624a20ddc17c6adf26464 (patch)
tree65bfd436ffe0c64ad7306f928bdf85decb695e7f
parentdb4f51dd64ae0f428468338af01a582aaed26fde (diff)
call inference!!!
-rw-r--r--infer.c7
-rw-r--r--test.toc7
-rw-r--r--types.c4
3 files changed, 9 insertions, 9 deletions
diff --git a/infer.c b/infer.c
index 28b11a2..bd0ffa0 100644
--- a/infer.c
+++ b/infer.c
@@ -23,18 +23,18 @@ static bool infer_from_expr(Typer *tr, Expression *match, Expression *to, Identi
break;
case EXPR_CALL: {
if (to->kind != EXPR_CALL) return true; /* give up */
- puts("wow call");
Argument *m_args = match->call.args;
Expression *t_args = to->call.arg_exprs;
size_t nargs = arr_len(m_args);
U16 *order = NULL;
Expression *f = match->call.fn;
-
IdentDecl *idecl = ident_decl(f->ident);
bool is_direct_fn = idecl && idecl->kind == IDECL_DECL && (idecl->decl->flags & DECL_HAS_EXPR) && idecl->decl->expr.kind == EXPR_FN;
if (is_direct_fn) {
- FnExpr *fn_decl = idecl->decl->expr.fn;
+ if (!types_expr(tr, f))
+ return false;
+ FnExpr *fn_decl = idecl->decl->expr.fn;
if (!call_arg_param_order(tr->allocr, fn_decl, idecl->decl->where, &f->type, m_args, match->where, &order))
return false;
}
@@ -109,7 +109,6 @@ static bool infer_from_type(Typer *tr, Type *match, Type *to, Identifier *idents
} break;
case TYPE_EXPR: {
Expression *to_expr = to->was_expr;
- print_type(to);
Expression e = {0};
if (!to_expr) {
to_expr = &e;
diff --git a/test.toc b/test.toc
index c13c093..24c5701 100644
--- a/test.toc
+++ b/test.toc
@@ -7,11 +7,12 @@ putf ::= fn(x: float) {
t ::= fn(a:: Type) Type {a};
-f ::= fn(b::=, a:t(b)) int{
-3
+f ::= fn(b::=, u::=, a:t(b), x:t(u)) int{
+((3 as b) as u) as int
};
main ::= fn() {
x : t(int) = 3;
- f(x);
+ y : t(float) = 3.4;
+ f(x,y);
}; \ No newline at end of file
diff --git a/types.c b/types.c
index 8a097f7..d4bac24 100644
--- a/types.c
+++ b/types.c
@@ -501,11 +501,11 @@ static bool type_resolve(Typer *tr, Type *t, Location where) {
Value typeval;
if (!types_expr(tr, t->expr))
return false;
- print_expr(t->expr);
- t->was_expr = t->expr;
+ Expression *expr = t->expr;
if (!eval_expr(tr->evalr, t->expr, &typeval))
return false;
*t = *typeval.type;
+ t->was_expr = expr;
assert(t->flags & TYPE_IS_RESOLVED);
} break;
case TYPE_UNKNOWN: