diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-11-30 15:54:21 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-11-30 15:54:21 -0500 |
| commit | 919e47a4188acc1da711ac05e5aa097a3b1349f7 (patch) | |
| tree | a5ee13c04109d91ff9a1cd787f9ea63645361f92 | |
| parent | 40c33987fa0a91a8525d960f8494ca9ddf12806d (diff) | |
Better error messages for `table[key] += ...`
| -rw-r--r-- | compile.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -618,6 +618,13 @@ CORD compile_statement(env_t *env, ast_t *ast) } else if (test->expr->tag == UpdateAssign) { type_t *lhs_t = get_type(env, Match(test->expr, UpdateAssign)->lhs); auto update = Match(test->expr, UpdateAssign); + + if (update->lhs->tag == Index) { + type_t *indexed = value_type(get_type(env, Match(update->lhs, Index)->indexed)); + if (indexed->tag == TableType) + code_err(update->lhs, "Update assignments are not currently supported for tables"); + } + ast_t *update_var = WrapAST(ast, UpdateAssign, .lhs=WrapAST(update->lhs, InlineCCode, .code="(*expr)", .type=lhs_t), .op=update->op, .rhs=update->rhs); @@ -692,6 +699,13 @@ CORD compile_statement(env_t *env, ast_t *ast) } case UpdateAssign: { auto update = Match(ast, UpdateAssign); + + if (update->lhs->tag == Index) { + type_t *indexed = value_type(get_type(env, Match(update->lhs, Index)->indexed)); + if (indexed->tag == TableType) + code_err(update->lhs, "Update assignments are not currently supported for tables"); + } + if (!is_idempotent(update->lhs)) { type_t *lhs_t = get_type(env, update->lhs); return CORD_all("{ ", compile_declaration(Type(PointerType, lhs_t), "update_lhs"), " = &", |
