checker: change non-const size of fixed array error message (#8850)

pull/8857/head
yuyi 2021-02-20 19:14:44 +08:00 committed by GitHub
parent 859d382c6e
commit 5e1159e4c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 5 deletions

View File

@ -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 {

View File

@ -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)

View File

@ -0,0 +1,7 @@
fn main() {
size := 2
array := [size]int{}
println(array)
}

View File

@ -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 {