From b9b53e6cd5687f62fc985c37474cc8bb220aa3ae Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 27 Jul 2024 16:34:20 -0300 Subject: [PATCH] parser: improve the error message position for invalid array attr keys (#21944) --- vlib/v/checker/tests/wrong_arr_field_err.out | 4 ++++ vlib/v/checker/tests/wrong_arr_field_err.vv | 2 ++ vlib/v/parser/containers.v | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 vlib/v/checker/tests/wrong_arr_field_err.out create mode 100644 vlib/v/checker/tests/wrong_arr_field_err.vv diff --git a/vlib/v/checker/tests/wrong_arr_field_err.out b/vlib/v/checker/tests/wrong_arr_field_err.out new file mode 100644 index 000000000..e96937d38 --- /dev/null +++ b/vlib/v/checker/tests/wrong_arr_field_err.out @@ -0,0 +1,4 @@ +vlib/v/checker/tests/wrong_arr_field_err.vv:1:34: error: wrong field `init1`, expecting `len`, `cap`, or `init` + 1 | arr := []int{len: 100, cap: 200, init1: index * 3} + | ~~~~~ + 2 | println(arr) diff --git a/vlib/v/checker/tests/wrong_arr_field_err.vv b/vlib/v/checker/tests/wrong_arr_field_err.vv new file mode 100644 index 000000000..ae40ffd9f --- /dev/null +++ b/vlib/v/checker/tests/wrong_arr_field_err.vv @@ -0,0 +1,2 @@ +arr := []int{len: 100, cap: 200, init1: index * 3} +println(arr) \ No newline at end of file diff --git a/vlib/v/parser/containers.v b/vlib/v/parser/containers.v index 1657df7c1..81d600670 100644 --- a/vlib/v/parser/containers.v +++ b/vlib/v/parser/containers.v @@ -157,7 +157,8 @@ fn (mut p Parser) array_init(is_option bool, alias_array_type ast.Type) ast.Arra has_index = p.handle_index_variable(mut init_expr) } else { - p.error('wrong field `${key}`, expecting `len`, `cap`, or `init`') + p.error_with_pos('wrong field `${key}`, expecting `len`, `cap`, or `init`', + attr_pos) return ast.ArrayInit{} } } -- 2.39.5