parser, checker: correct error message for a fixed array size using a non constant (fix #13219) (#13228)
parent
5143837d66
commit
d553071e65
|
@ -163,7 +163,7 @@ pub fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type {
|
|||
}
|
||||
}
|
||||
else {
|
||||
c.error('expecting `int` for fixed size', node.pos)
|
||||
c.error('fixed array size cannot use non-constant value', init_expr.position())
|
||||
}
|
||||
}
|
||||
if fixed_size <= 0 {
|
||||
|
|
|
@ -59,7 +59,8 @@ pub fn (mut p Parser) parse_array_type(expecting token.Kind) ast.Type {
|
|||
}
|
||||
}
|
||||
else {
|
||||
p.error('expecting `int` for fixed size')
|
||||
p.error_with_pos('fixed array size cannot use non-constant value',
|
||||
size_expr.position())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
vlib/v/parser/tests/fixed_array_size_using_non_constant_err.vv:9:25: error: fixed array size cannot use non-constant value
|
||||
7 | println(typeof(t.len).name)
|
||||
8 |
|
||||
9 | mut score := [t.len][t.len]int{}
|
||||
| ~~~
|
||||
10 | }
|
|
@ -0,0 +1,10 @@
|
|||
module main
|
||||
|
||||
fn main() {
|
||||
mut t := [0, 0]
|
||||
|
||||
println(t.len)
|
||||
println(typeof(t.len).name)
|
||||
|
||||
mut score := [t.len][t.len]int{}
|
||||
}
|
Loading…
Reference in New Issue