From 5e1159e4c33c35861824c454a8aa15a844b7f1ad Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 20 Feb 2021 19:14:44 +0800 Subject: [PATCH] checker: change non-const size of fixed array error message (#8850) --- vlib/v/checker/checker.v | 3 +-- vlib/v/checker/tests/fixed_array_non_const_size_err.out | 7 +++++++ vlib/v/checker/tests/fixed_array_non_const_size_err.vv | 7 +++++++ vlib/v/parser/parse_type.v | 5 ++--- 4 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 vlib/v/checker/tests/fixed_array_non_const_size_err.out create mode 100644 vlib/v/checker/tests/fixed_array_non_const_size_err.vv diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index aacc2c41b7..5ef8c2e620 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2993,8 +2993,7 @@ pub fn (mut c Checker) array_init(mut array_init ast.ArrayInit) table.Type { fixed_size = cint } } else { - c.error('non existent integer const $init_expr.name while initializing the size of a static array', - array_init.pos) + c.error('non-constant array bound `$init_expr.name`', init_expr.pos) } } else { diff --git a/vlib/v/checker/tests/fixed_array_non_const_size_err.out b/vlib/v/checker/tests/fixed_array_non_const_size_err.out new file mode 100644 index 0000000000..073492085f --- /dev/null +++ b/vlib/v/checker/tests/fixed_array_non_const_size_err.out @@ -0,0 +1,7 @@ +vlib/v/checker/tests/fixed_array_non_const_size_err.vv:4:12: error: non-constant array bound `size` + 2 | size := 2 + 3 | + 4 | array := [size]int{} + | ~~~~ + 5 | + 6 | println(array) diff --git a/vlib/v/checker/tests/fixed_array_non_const_size_err.vv b/vlib/v/checker/tests/fixed_array_non_const_size_err.vv new file mode 100644 index 0000000000..eada0cd4bf --- /dev/null +++ b/vlib/v/checker/tests/fixed_array_non_const_size_err.vv @@ -0,0 +1,7 @@ +fn main() { + size := 2 + + array := [size]int{} + + println(array) +} diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index 95cdc66833..e35117f583 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -22,12 +22,11 @@ pub fn (mut p Parser) parse_array_type() table.Type { if const_field.expr is ast.IntegerLiteral { fixed_size = const_field.expr.val.int() } else { - p.error_with_pos('non existent integer const $size_expr.name while initializing the size of a static array', + p.error_with_pos('non-constant array bound `$size_expr.name`', size_expr.pos) } } else { - p.error_with_pos('non existent integer const $size_expr.name while initializing the size of a static array', - size_expr.pos) + p.error_with_pos('non-constant array bound `$size_expr.name`', size_expr.pos) } } else {