mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: don't panic on non-array decomposition (#7836)
This commit is contained in:
parent
91a1a2877b
commit
529f46d808
@ -398,7 +398,7 @@ pub fn (mut c Checker) struct_decl(decl ast.StructDecl) {
|
|||||||
field.type_pos)
|
field.type_pos)
|
||||||
}
|
}
|
||||||
// Separate error condition for `any_int` and `any_float` because `util.suggestion` may give different
|
// Separate error condition for `any_int` and `any_float` because `util.suggestion` may give different
|
||||||
// suggestions due to f32 comparision issue.
|
// suggestions due to f32 comparision issue.
|
||||||
if sym.kind in [.any_int, .any_float] {
|
if sym.kind in [.any_int, .any_float] {
|
||||||
msg := if sym.kind == .any_int {
|
msg := if sym.kind == .any_int {
|
||||||
'unknown type `$sym.name`.\nDid you mean `int`?'
|
'unknown type `$sym.name`.\nDid you mean `int`?'
|
||||||
@ -3049,7 +3049,8 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
|
|||||||
typ := c.expr(node.expr)
|
typ := c.expr(node.expr)
|
||||||
type_sym := c.table.get_type_symbol(typ)
|
type_sym := c.table.get_type_symbol(typ)
|
||||||
if type_sym.kind != .array {
|
if type_sym.kind != .array {
|
||||||
c.error('expected array', node.pos)
|
c.error('decomposition can only be used on arrays', node.expr.position())
|
||||||
|
return table.void_type
|
||||||
}
|
}
|
||||||
array_info := type_sym.info as table.Array
|
array_info := type_sym.info as table.Array
|
||||||
elem_type := array_info.elem_type.set_flag(.variadic)
|
elem_type := array_info.elem_type.set_flag(.variadic)
|
||||||
|
6
vlib/v/checker/tests/decompose_type_err.out
Normal file
6
vlib/v/checker/tests/decompose_type_err.out
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
vlib/v/checker/tests/decompose_type_err.vv:4:10: error: decomposition can only be used on arrays
|
||||||
|
2 |
|
||||||
|
3 | fn main() {
|
||||||
|
4 | varargs(123...)
|
||||||
|
| ~~~
|
||||||
|
5 | }
|
5
vlib/v/checker/tests/decompose_type_err.vv
Normal file
5
vlib/v/checker/tests/decompose_type_err.vv
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
fn varargs(a ...int) { println(a) }
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
varargs(123...)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user