From cc16de6920b3a64c5014350cc46761c2b86290b9 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Sun, 8 Dec 2019 17:53:31 -0500 Subject: fixed problem with flexible types --- test.toc | 2 +- types.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/test.toc b/test.toc index 72282d4..3ea56d1 100644 --- a/test.toc +++ b/test.toc @@ -3,5 +3,5 @@ f ::= fn(y:f64=19.2) { }; main ::= fn() { - f(); + f(13); }; diff --git a/types.c b/types.c index 5a2c946..a65d8d6 100644 --- a/types.c +++ b/types.c @@ -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; -- cgit v1.2.3