mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: change non-const size of fixed array error message (#8850)
This commit is contained in:
parent
859d382c6e
commit
5e1159e4c3
@ -2993,8 +2993,7 @@ pub fn (mut c Checker) array_init(mut array_init ast.ArrayInit) table.Type {
|
|||||||
fixed_size = cint
|
fixed_size = cint
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.error('non existent integer const $init_expr.name while initializing the size of a static array',
|
c.error('non-constant array bound `$init_expr.name`', init_expr.pos)
|
||||||
array_init.pos)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
7
vlib/v/checker/tests/fixed_array_non_const_size_err.out
Normal file
7
vlib/v/checker/tests/fixed_array_non_const_size_err.out
Normal 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)
|
7
vlib/v/checker/tests/fixed_array_non_const_size_err.vv
Normal file
7
vlib/v/checker/tests/fixed_array_non_const_size_err.vv
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fn main() {
|
||||||
|
size := 2
|
||||||
|
|
||||||
|
array := [size]int{}
|
||||||
|
|
||||||
|
println(array)
|
||||||
|
}
|
@ -22,12 +22,11 @@ pub fn (mut p Parser) parse_array_type() table.Type {
|
|||||||
if const_field.expr is ast.IntegerLiteral {
|
if const_field.expr is ast.IntegerLiteral {
|
||||||
fixed_size = const_field.expr.val.int()
|
fixed_size = const_field.expr.val.int()
|
||||||
} else {
|
} 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)
|
size_expr.pos)
|
||||||
}
|
}
|
||||||
} else {
|
} 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)
|
||||||
size_expr.pos)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user