From 3c64616ac1f7a0ae6ac66281a2a11e1487f4747e Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 23 Apr 2024 12:54:56 -0400 Subject: Bugfix for doctest assignments that promote --- compile.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/compile.c b/compile.c index 09507212..850f2e2a 100644 --- a/compile.c +++ b/compile.c @@ -254,8 +254,14 @@ CORD compile_statement(env_t *env, ast_t *ast) CORD code = "{ // Assignment\n"; int64_t i = 1; - for (ast_list_t *value = assign->values; value; value = value->next) - CORD_appendf(&code, "%r $%ld = %r;\n", compile_type(env, get_type(env, value->ast)), i++, compile(env, value->ast)); + for (ast_list_t *target = assign->targets, *value = assign->values; target && value; target = target->next, value = value->next) { + type_t *target_type = get_type(env, target->ast); + type_t *value_type = get_type(env, value->ast); + CORD val_code = compile(env, value->ast); + if (!promote(env, &val_code, value_type, target_type)) + code_err(value->ast, "This %T value cannot be converted to a %T type", value_type, target_type); + CORD_appendf(&code, "%r $%ld = %r;\n", compile_type(env, target_type), i++, val_code); + } i = 1; for (ast_list_t *target = assign->targets; target; target = target->next) code = CORD_all(code, compile_assignment(env, target->ast, CORD_asprintf("$%ld", i++))); -- cgit v1.2.3