commit 62b883ac62dcdfc20afecacd0e4f7f680f569daf
parent c8cdca8b7b08f62bb7d660e4247082f7c4ff14d7
Author: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Date: Mon, 24 Jan 2022 05:28:41 +0100
improve error messages for syntactically invalid insert expressions
Signed-off-by: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Diffstat:
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/parse.c b/src/parse.c
@@ -1282,10 +1282,6 @@ parse_append_insert(struct lexer *lexer, struct location *loc,
want(lexer, T_LPAREN, NULL);
expr->append.object = parse_object_selector(lexer);
- if (etype == EXPR_INSERT) {
- synassert_msg(expr->append.object->access.type == ACCESS_INDEX,
- "expected indexing expression", &tok);
- }
want(lexer, T_COMMA, NULL);
expr->append.value = parse_expression(lexer);
expr->append.is_static = is_static;
@@ -1299,6 +1295,13 @@ parse_append_insert(struct lexer *lexer, struct location *loc,
break;
}
+ if (etype == EXPR_INSERT) {
+ synassert_msg(expr->append.object->access.type == ACCESS_INDEX,
+ "expected indexing expression", &tok);
+ want(lexer, T_RPAREN, NULL);
+ return expr;
+ }
+
switch (lex(lexer, &tok)) {
case T_RPAREN:
// This space deliberately left blank
diff --git a/tests/28-insert.ha b/tests/28-insert.ha
@@ -66,6 +66,11 @@ fn reject() void = {
let y: []int = [42];
insert(x[1], y...);
") != 0); // object member type != value member type
+ assert(rt::compile("
+ let x: []u8 = [0u8];
+ let y: []int = [42];
+ insert(x[1], [y...], 3);
+ ") != 0); // insert expression doesn't have a length parameter
};
export fn main() void = {