From bb95a276182e4a45c7b5dfb2f8a74866beeaa404 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 16 Sep 2023 18:41:39 +0300 Subject: [PATCH] parser: do not panic for `v -silent -check-syntax bug.v`, where bug.v is `mut z_buffer := [][]` --- vlib/v/parser/containers.v | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/vlib/v/parser/containers.v b/vlib/v/parser/containers.v index 599d44c845fb21..963811c40d0121 100644 --- a/vlib/v/parser/containers.v +++ b/vlib/v/parser/containers.v @@ -33,16 +33,18 @@ fn (mut p Parser) array_init(is_option bool) ast.ArrayInit { elem_type = p.parse_type() // this is set here because it's a known type, others could be the // result of expr so we do those in checker - idx := p.table.find_or_register_array(elem_type) - if elem_type.has_flag(.generic) { - array_type = ast.new_type(idx).set_flag(.generic) - } else { - array_type = ast.new_type(idx) - } - if is_option { - array_type = array_type.set_flag(.option) + if elem_type != 0 { + idx := p.table.find_or_register_array(elem_type) + if elem_type.has_flag(.generic) { + array_type = ast.new_type(idx).set_flag(.generic) + } else { + array_type = ast.new_type(idx) + } + if is_option { + array_type = array_type.set_flag(.option) + } + has_type = true } - has_type = true } last_pos = p.tok.pos() } else {