aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-11-30 15:54:21 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-11-30 15:54:21 -0500
commit919e47a4188acc1da711ac05e5aa097a3b1349f7 (patch)
treea5ee13c04109d91ff9a1cd787f9ea63645361f92
parent40c33987fa0a91a8525d960f8494ca9ddf12806d (diff)
Better error messages for `table[key] += ...`
-rw-r--r--compile.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/compile.c b/compile.c
index 82449927..ee06e957 100644
--- a/compile.c
+++ b/compile.c
@@ -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"), " = &",