aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-11-09 16:59:34 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-11-09 16:59:34 -0500
commit8dd51a113ead1fe88c80af9165219ca5398715f6 (patch)
tree528f76c71f71c3b30d18a8af3e256ff1c5414a48
parent06d3ec138003e412d8a2adde71969f01a25fe96a (diff)
Bugfix integer literal demotion in assignment statements
-rw-r--r--compile.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/compile.c b/compile.c
index 8f0043cc..66f2c9a8 100644
--- a/compile.c
+++ b/compile.c
@@ -637,12 +637,12 @@ CORD compile_statement(env_t *env, ast_t *ast)
env_t *val_env = with_enum_scope(env, lhs_t);
type_t *rhs_t = get_type(val_env, assign->values->ast);
CORD val;
- if (rhs_t->tag == IntType && assign->values->ast->tag == Int) {
- val = compile_int_to_type(val_env, assign->values->ast, rhs_t);
+ if (lhs_t->tag == IntType && assign->values->ast->tag == Int) {
+ val = compile_int_to_type(val_env, assign->values->ast, lhs_t);
} else {
val = compile_maybe_incref(val_env, assign->values->ast);
if (!promote(val_env, &val, rhs_t, lhs_t))
- code_err(assign->values->ast, "You cannot assign a %T value to a %T operand", lhs_t, rhs_t);
+ code_err(assign->values->ast, "You cannot assign a %T value to a %T operand", rhs_t, lhs_t);
}
return CORD_all(compile_assignment(env, assign->targets->ast, val), ";\n");
}