File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -169,7 +169,15 @@ fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type {
169
169
}
170
170
}
171
171
for i, mut expr in node.exprs {
172
- mut typ := c.check_expr_option_or_result_call (expr, c.expr (mut expr))
172
+ mut typ := ast.void_type
173
+ if expr is ast.ArrayInit {
174
+ old_expected_type := c.expected_type
175
+ c.expected_type = c.table.value_type (c.expected_type)
176
+ typ = c.check_expr_option_or_result_call (expr, c.expr (mut expr))
177
+ c.expected_type = old_expected_type
178
+ } else {
179
+ typ = c.check_expr_option_or_result_call (expr, c.expr (mut expr))
180
+ }
173
181
if expr is ast.CallExpr {
174
182
ret_sym := c.table.sym (typ)
175
183
if ret_sym.kind == .array_fixed {
Original file line number Diff line number Diff line change
1
+ fn test_3dims () {
2
+ mut array := [][][]int {}
3
+ array << [[1 ]]
4
+ dump (array)
5
+ array << [[[1 ]]]
6
+ dump (array)
7
+ array << [[[]]]
8
+ println (array)
9
+ assert array == [[[int (1 )]], [[1 ]], [[]int {}]]
10
+ }
11
+
12
+ fn test_2dims () {
13
+ mut array := [][]int {}
14
+ array << [1 ]
15
+ dump (array)
16
+ array << [[1 ]]
17
+ dump (array)
18
+ array << [[]]
19
+ println (array)
20
+ assert array == [[int (1 )], [1 ], []int {}]
21
+ }
You can’t perform that action at this time.
0 commit comments