diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2019-12-08 17:53:31 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2019-12-08 17:53:31 -0500 |
commit | cc16de6920b3a64c5014350cc46761c2b86290b9 (patch) | |
tree | 5af459a93e5cb5b7bc1f271e23c972d5f59cd0e0 | |
parent | 3db3e1a84fcded750ccf45732c6527e1581bc36e (diff) |
fixed problem with flexible types
-rw-r--r-- | test.toc | 2 | ||||
-rw-r--r-- | types.c | 9 |
2 files changed, 8 insertions, 3 deletions
@@ -3,5 +3,5 @@ f ::= fn(y:f64=19.2) { }; main ::= fn() { - f(); + f(13); }; @@ -249,6 +249,13 @@ static bool type_of_fn(Typer *tr, FnExpr *f, Location where, Type *t, U16 flags) } param->expr.kind = EXPR_VAL; param->expr.val = val; + if (param->expr.type.flags & TYPE_IS_FLEXIBLE) { + /* cast to the annotated type, if one exists */ + if (param->flags & DECL_ANNOTATES_TYPE) { + val_cast(¶m->expr.val, ¶m->expr.type, ¶m->expr.val, ¶m->type); + param->expr.type = param->type; + } + } } } } @@ -1189,7 +1196,6 @@ static bool types_expr(Typer *tr, Expression *e) { if (should_be_evald && params_set[i]) { Expression *expr = &arg_exprs[i]; - Value *arg_val = typer_arr_add(tr, &table_index.tuple); if (!eval_expr(tr->evalr, expr, arg_val)) { if (tr->evalr->enabled) { @@ -1205,7 +1211,6 @@ static bool types_expr(Typer *tr, Expression *e) { arg_exprs[i].flags = EXPR_FOUND_TYPE; copy_val(tr->allocr, &arg_exprs[i].val, arg_val, type); arg_exprs[i].val = *arg_val; - arg_exprs[i].type = *type; copy_val(tr->allocr, ¶m_decl->val, arg_val, type); param_decl->flags |= DECL_FOUND_VAL; |