diff options
-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; |