checker: detect correct len expression for multidimensional array init (#6521)
parent
417b1450b5
commit
8152b86652
|
@ -1032,3 +1032,18 @@ fn test_direct_array_access_via_ptr() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
grid_size_1 = 2
|
||||||
|
grid_size_2 = 3
|
||||||
|
grid_size_3 = 4
|
||||||
|
cell_value = 123
|
||||||
|
)
|
||||||
|
|
||||||
|
fn test_multidimensional_array_initialization_with_consts() {
|
||||||
|
mut data := [][][]int{ len: grid_size_1, init: [][]int{ len: grid_size_2, init: []int{ len: grid_size_3, init: cell_value } } }
|
||||||
|
assert data.len == grid_size_1
|
||||||
|
assert data[0].len == grid_size_2
|
||||||
|
assert data[0][0].len == grid_size_3
|
||||||
|
assert data[0][0][0] == cell_value
|
||||||
|
assert data[1][1][1] == cell_value
|
||||||
|
}
|
||||||
|
|
|
@ -2070,6 +2070,9 @@ pub fn (mut c Checker) array_init(mut array_init ast.ArrayInit) table.Type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sym := c.table.get_type_symbol(array_init.elem_type)
|
sym := c.table.get_type_symbol(array_init.elem_type)
|
||||||
|
if array_init.has_default {
|
||||||
|
c.expr(array_init.default_expr)
|
||||||
|
}
|
||||||
if sym.kind == .placeholder {
|
if sym.kind == .placeholder {
|
||||||
c.error('unknown type `$sym.source_name`', array_init.elem_type_pos)
|
c.error('unknown type `$sym.source_name`', array_init.elem_type_pos)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue