1
0
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:
Enzo 2021-01-03 15:45:39 +01:00 committed by GitHub
parent 91a1a2877b
commit 529f46d808
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View File

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

View 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 | }

View File

@ -0,0 +1,5 @@
fn varargs(a ...int) { println(a) }
fn main() {
varargs(123...)
}