Fix for update assignments

This commit is contained in:
Bruce Hill 2024-11-30 15:33:54 -05:00
parent e38ecde989
commit 357c9faa40
2 changed files with 3 additions and 2 deletions

View File

@ -359,7 +359,7 @@ static CORD compile_lvalue(env_t *env, ast_t *ast)
} else {
code_err(ast, "I don't know how to assign to this target");
}
} else if (ast->tag == Var || ast->tag == FieldAccess) {
} else if (ast->tag == Var || ast->tag == FieldAccess || ast->tag == InlineCCode) {
return compile(env, ast);
} else {
code_err(ast, "I don't know how to assign to this");
@ -610,7 +610,7 @@ CORD compile_statement(env_t *env, ast_t *ast)
type_t *lhs_t = get_type(env, Match(test->expr, UpdateAssign)->lhs);
auto update = Match(test->expr, UpdateAssign);
ast_t *update_var = WrapAST(ast, UpdateAssign,
.lhs=WrapAST(update->lhs, Index, .indexed=WrapAST(update->lhs, InlineCCode, .code="expr", .type=Type(PointerType, lhs_t))),
.lhs=WrapAST(update->lhs, InlineCCode, .code="(*expr)", .type=lhs_t),
.op=update->op, .rhs=update->rhs);
return CORD_asprintf(
"test(({%r = &(%r); %r; *expr;}), %r, %r, %ld, %ld);",

View File

@ -1292,6 +1292,7 @@ PUREFUNC bool can_be_mutated(env_t *env, ast_t *ast)
{
switch (ast->tag) {
case Var: return true;
case InlineCCode: return true;
case FieldAccess: {
auto access = Match(ast, FieldAccess);
type_t *fielded_type = get_type(env, access->fielded);