authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-13 13:31:15-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-13 13:31:15-04:00
logefb064449f4db63c1e841f6f0e434f26fcd487ab
tree44073f801cd144bfbc4291550d79927977cf1713
parentca0988e1d01bd121100590fb97f8cd9dde15b7d8
signature Commit is signed but in an unrecognized format.

fix runtime initialize array elem and then implicit cast to slice


4 files changed, 141 insertions(+), 123 deletions(-)

src/all_types.hpp+3-1
...@@ -2555,8 +2555,8 @@ struct IrInstructionElemPtr {...@@ -2555,8 +2555,8 @@ struct IrInstructionElemPtr {
2555 IrInstruction *array_ptr;2555 IrInstruction *array_ptr;
2556 IrInstruction *elem_index;2556 IrInstruction *elem_index;
2557 PtrLen ptr_len;2557 PtrLen ptr_len;
2558 bool is_const;
2559 bool safety_check_on;2558 bool safety_check_on;
2559 bool initializing;
2560};2560};
25612561
2562struct IrInstructionVarPtr {2562struct IrInstructionVarPtr {
...@@ -2651,6 +2651,7 @@ struct IrInstructionContainerInitList {...@@ -2651,6 +2651,7 @@ struct IrInstructionContainerInitList {
2651 IrInstruction *elem_type;2651 IrInstruction *elem_type;
2652 size_t item_count;2652 size_t item_count;
2653 IrInstruction **items;2653 IrInstruction **items;
2654 ResultLoc *result_loc;
2654};2655};
26552656
2656struct IrInstructionContainerInitFieldsField {2657struct IrInstructionContainerInitFieldsField {
...@@ -2666,6 +2667,7 @@ struct IrInstructionContainerInitFields {...@@ -2666,6 +2667,7 @@ struct IrInstructionContainerInitFields {
2666 IrInstruction *container_type;2667 IrInstruction *container_type;
2667 size_t field_count;2668 size_t field_count;
2668 IrInstructionContainerInitFieldsField *fields;2669 IrInstructionContainerInitFieldsField *fields;
2670 ResultLoc *result_loc;
2669};2671};
26702672
2671struct IrInstructionUnreachable {2673struct IrInstructionUnreachable {
src/ir.cpp+37-27
...@@ -1298,14 +1298,16 @@ static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_...@@ -1298,14 +1298,16 @@ static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_
1298 return &instruction->base;1298 return &instruction->base;
1299}1299}
13001300
1301static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *array_ptr,1301static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
1302 IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len)1302 IrInstruction *array_ptr, IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len,
1303 bool initializing)
1303{1304{
1304 IrInstructionElemPtr *instruction = ir_build_instruction<IrInstructionElemPtr>(irb, scope, source_node);1305 IrInstructionElemPtr *instruction = ir_build_instruction<IrInstructionElemPtr>(irb, scope, source_node);
1305 instruction->array_ptr = array_ptr;1306 instruction->array_ptr = array_ptr;
1306 instruction->elem_index = elem_index;1307 instruction->elem_index = elem_index;
1307 instruction->safety_check_on = safety_check_on;1308 instruction->safety_check_on = safety_check_on;
1308 instruction->ptr_len = ptr_len;1309 instruction->ptr_len = ptr_len;
1310 instruction->initializing = initializing;
13091311
1310 ir_ref_instruction(array_ptr, irb->current_basic_block);1312 ir_ref_instruction(array_ptr, irb->current_basic_block);
1311 ir_ref_instruction(elem_index, irb->current_basic_block);1313 ir_ref_instruction(elem_index, irb->current_basic_block);
...@@ -1505,13 +1507,14 @@ static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *sour...@@ -1505,13 +1507,14 @@ static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *sour
1505}1507}
15061508
1507static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, AstNode *source_node,1509static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, AstNode *source_node,
1508 IrInstruction *container_type, size_t item_count, IrInstruction **items)1510 IrInstruction *container_type, size_t item_count, IrInstruction **items, ResultLoc *result_loc)
1509{1511{
1510 IrInstructionContainerInitList *container_init_list_instruction =1512 IrInstructionContainerInitList *container_init_list_instruction =
1511 ir_build_instruction<IrInstructionContainerInitList>(irb, scope, source_node);1513 ir_build_instruction<IrInstructionContainerInitList>(irb, scope, source_node);
1512 container_init_list_instruction->container_type = container_type;1514 container_init_list_instruction->container_type = container_type;
1513 container_init_list_instruction->item_count = item_count;1515 container_init_list_instruction->item_count = item_count;
1514 container_init_list_instruction->items = items;1516 container_init_list_instruction->items = items;
1517 container_init_list_instruction->result_loc = result_loc;
15151518
1516 ir_ref_instruction(container_type, irb->current_basic_block);1519 ir_ref_instruction(container_type, irb->current_basic_block);
1517 for (size_t i = 0; i < item_count; i += 1) {1520 for (size_t i = 0; i < item_count; i += 1) {
...@@ -1522,13 +1525,15 @@ static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope,...@@ -1522,13 +1525,15 @@ static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope,
1522}1525}
15231526
1524static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scope, AstNode *source_node,1527static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scope, AstNode *source_node,
1525 IrInstruction *container_type, size_t field_count, IrInstructionContainerInitFieldsField *fields)1528 IrInstruction *container_type, size_t field_count, IrInstructionContainerInitFieldsField *fields,
1529 ResultLoc *result_loc)
1526{1530{
1527 IrInstructionContainerInitFields *container_init_fields_instruction =1531 IrInstructionContainerInitFields *container_init_fields_instruction =
1528 ir_build_instruction<IrInstructionContainerInitFields>(irb, scope, source_node);1532 ir_build_instruction<IrInstructionContainerInitFields>(irb, scope, source_node);
1529 container_init_fields_instruction->container_type = container_type;1533 container_init_fields_instruction->container_type = container_type;
1530 container_init_fields_instruction->field_count = field_count;1534 container_init_fields_instruction->field_count = field_count;
1531 container_init_fields_instruction->fields = fields;1535 container_init_fields_instruction->fields = fields;
1536 container_init_fields_instruction->result_loc = result_loc;
15321537
1533 ir_ref_instruction(container_type, irb->current_basic_block);1538 ir_ref_instruction(container_type, irb->current_basic_block);
1534 for (size_t i = 0; i < field_count; i += 1) {1539 for (size_t i = 0; i < field_count; i += 1) {
...@@ -4202,7 +4207,7 @@ static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode...@@ -4202,7 +4207,7 @@ static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode
4202 return subscript_instruction;4207 return subscript_instruction;
42034208
4204 IrInstruction *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction,4209 IrInstruction *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction,
4205 subscript_instruction, true, PtrLenSingle);4210 subscript_instruction, true, PtrLenSingle, false);
4206 if (lval == LValPtr)4211 if (lval == LValPtr)
4207 return ptr_instruction;4212 return ptr_instruction;
42084213
...@@ -5734,7 +5739,8 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -5734,7 +5739,8 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
5734 fields[i].value = expr_value;5739 fields[i].value = expr_value;
5735 fields[i].source_node = entry_node;5740 fields[i].source_node = entry_node;
5736 }5741 }
5737 IrInstruction *init_fields = ir_build_container_init_fields(irb, scope, node, container_type, field_count, fields);5742 IrInstruction *init_fields = ir_build_container_init_fields(irb, scope, node, container_type,
5743 field_count, fields, result_loc);
57385744
5739 return ir_lval_wrap(irb, scope, init_fields, lval, result_loc);5745 return ir_lval_wrap(irb, scope, init_fields, lval, result_loc);
5740 }5746 }
...@@ -5764,7 +5770,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -5764,7 +5770,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
5764 if (container_ptr != nullptr) {5770 if (container_ptr != nullptr) {
5765 IrInstruction *elem_index = ir_build_const_usize(irb, &result_loc->scope_elide->base, expr_node, i);5771 IrInstruction *elem_index = ir_build_const_usize(irb, &result_loc->scope_elide->base, expr_node, i);
5766 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, &result_loc->scope_elide->base, expr_node,5772 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, &result_loc->scope_elide->base, expr_node,
5767 container_ptr, elem_index, false, PtrLenSingle);5773 container_ptr, elem_index, false, PtrLenSingle, true);
5768 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);5774 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
5769 result_loc_inst->base.id = ResultLocIdInstruction;5775 result_loc_inst->base.id = ResultLocIdInstruction;
5770 result_loc_inst->base.source_instruction = elem_ptr;5776 result_loc_inst->base.source_instruction = elem_ptr;
...@@ -5781,7 +5787,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -5781,7 +5787,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
5781 values[i] = expr_value;5787 values[i] = expr_value;
5782 }5788 }
5783 IrInstruction *init_list = ir_build_container_init_list(irb, scope, node, container_type,5789 IrInstruction *init_list = ir_build_container_init_list(irb, scope, node, container_type,
5784 item_count, values);5790 item_count, values, result_loc);
5785 return ir_lval_wrap(irb, scope, init_list, lval, result_loc);5791 return ir_lval_wrap(irb, scope, init_list, lval, result_loc);
5786 }5792 }
5787 }5793 }
...@@ -6264,7 +6270,8 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -6264,7 +6270,8 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
6264 is_comptime);6270 is_comptime);
62656271
6266 ir_set_cursor_at_end_and_append_block(irb, body_block);6272 ir_set_cursor_at_end_and_append_block(irb, body_block);
6267 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, parent_scope, node, array_val_ptr, index_val, false, PtrLenSingle);6273 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, parent_scope, node, array_val_ptr, index_val, false,
6274 PtrLenSingle, false);
6268 // TODO make it an error to write to element variable or i variable.6275 // TODO make it an error to write to element variable or i variable.
6269 Buf *elem_var_name = elem_node->data.symbol_expr.symbol;6276 Buf *elem_var_name = elem_node->data.symbol_expr.symbol;
6270 ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime);6277 ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime);
...@@ -16825,8 +16832,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -16825,8 +16832,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
16825 } else if (is_slice(array_type)) {16832 } else if (is_slice(array_type)) {
16826 ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index];16833 ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index];
16827 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {16834 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
16828 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node,16835 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
16829 array_ptr, casted_elem_index, false, elem_ptr_instruction->ptr_len);16836 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false,
16837 elem_ptr_instruction->ptr_len, true);
16830 result->value.type = return_type;16838 result->value.type = return_type;
16831 return result;16839 return result;
16832 }16840 }
...@@ -16917,8 +16925,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -16917,8 +16925,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
16917 }16925 }
16918 }16926 }
1691916927
16920 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node,16928 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
16921 array_ptr, casted_elem_index, safety_check_on, elem_ptr_instruction->ptr_len);16929 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on,
16930 elem_ptr_instruction->ptr_len, elem_ptr_instruction->initializing);
16922 result->value.type = return_type;16931 result->value.type = return_type;
16923 return result;16932 return result;
16924}16933}
...@@ -18784,7 +18793,8 @@ static IrInstruction *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrI...@@ -18784,7 +18793,8 @@ static IrInstruction *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrI
18784}18793}
1878518794
18786static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction,18795static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction,
18787 ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)18796 ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields,
18797 ResultLoc *result_loc_pass1)
18788{18798{
18789 Error err;18799 Error err;
18790 if (container_type->id == ZigTypeIdUnion) {18800 if (container_type->id == ZigTypeIdUnion) {
...@@ -18919,11 +18929,11 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc...@@ -18919,11 +18929,11 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
18919 return ira->codegen->invalid_instruction;18929 return ira->codegen->invalid_instruction;
18920 }18930 }
1892118931
18922 // this instruction should not get to codegen18932 IrInstruction *result_loc = ir_resolve_result(ira, instruction, result_loc_pass1,
18923 IrInstruction *result = ir_const(ira, instruction, container_type);18933 container_type, nullptr);
18924 // this is how we signal to EndExpr the value is not comptime known18934 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))
18925 result->value.special = ConstValSpecialRuntime;18935 return result_loc;
18926 return result;18936 return ir_get_deref(ira, instruction, result_loc, nullptr);
18927}18937}
1892818938
18929static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,18939static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
...@@ -18942,8 +18952,8 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -18942,8 +18952,8 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
18942 buf_sprintf("expected array type or [_], found slice"));18952 buf_sprintf("expected array type or [_], found slice"));
18943 return ira->codegen->invalid_instruction;18953 return ira->codegen->invalid_instruction;
18944 } else if (container_type->id == ZigTypeIdStruct && !is_slice(container_type) && elem_count == 0) {18954 } else if (container_type->id == ZigTypeIdStruct && !is_slice(container_type) && elem_count == 0) {
18945 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,18955 return ir_analyze_container_init_fields(ira, &instruction->base, container_type, 0, nullptr,
18946 0, nullptr);18956 instruction->result_loc);
18947 } else if (container_type->id == ZigTypeIdArray) {18957 } else if (container_type->id == ZigTypeIdArray) {
18948 // array is same as slice init but we make a compile error if the length is wrong18958 // array is same as slice init but we make a compile error if the length is wrong
18949 ZigType *child_type;18959 ZigType *child_type;
...@@ -19029,11 +19039,11 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -19029,11 +19039,11 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
19029 return ira->codegen->invalid_instruction;19039 return ira->codegen->invalid_instruction;
19030 }19040 }
1903119041
19032 // this instruction should not get to codegen19042 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
19033 IrInstruction *new_instruction = ir_const(ira, &instruction->base, fixed_size_array_type);19043 fixed_size_array_type, nullptr);
19034 // this is how we signal to EndExpr the value is not comptime known19044 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))
19035 new_instruction->value.special = ConstValSpecialRuntime;19045 return result_loc;
19036 return new_instruction;19046 return ir_get_deref(ira, &instruction->base, result_loc, nullptr);
19037 } else if (container_type->id == ZigTypeIdVoid) {19047 } else if (container_type->id == ZigTypeIdVoid) {
19038 if (elem_count != 0) {19048 if (elem_count != 0) {
19039 ir_add_error_node(ira, instruction->base.source_node,19049 ir_add_error_node(ira, instruction->base.source_node,
...@@ -19058,7 +19068,7 @@ static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ir...@@ -19058,7 +19068,7 @@ static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ir
19058 return ira->codegen->invalid_instruction;19068 return ira->codegen->invalid_instruction;
1905919069
19060 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,19070 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,
19061 instruction->field_count, instruction->fields);19071 instruction->field_count, instruction->fields, instruction->result_loc);
19062}19072}
1906319073
19064static IrInstruction *ir_analyze_instruction_compile_err(IrAnalyze *ira,19074static IrInstruction *ir_analyze_instruction_compile_err(IrAnalyze *ira,
test/stage1/behavior.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1comptime {1comptime {
2 _ = @import("behavior/align.zig");2 _ = @import("behavior/align.zig");
3 _ = @import("behavior/alignof.zig");3 _ = @import("behavior/alignof.zig");
4 //_ = @import("behavior/array.zig");4 _ = @import("behavior/array.zig");
5 _ = @import("behavior/asm.zig");5 _ = @import("behavior/asm.zig");
6 //_ = @import("behavior/atomics.zig");6 //_ = @import("behavior/atomics.zig");
7 _ = @import("behavior/bit_shifting.zig");7 _ = @import("behavior/bit_shifting.zig");
test/stage1/behavior/array.zig+100-94
...@@ -172,99 +172,105 @@ fn plusOne(x: u32) u32 {...@@ -172,99 +172,105 @@ fn plusOne(x: u32) u32 {
172 return x + 1;172 return x + 1;
173}173}
174174
175test "array literal as argument to function" {175test "runtime initialize array elem and then implicit cast to slice" {
176 const S = struct {176 var two: i32 = 2;
177 fn entry(two: i32) void {177 const x: []const i32 = [_]i32{two};
178 foo([_]i32{178 expect(x[0] == 2);
179 1,
180 2,
181 3,
182 });
183 foo([_]i32{
184 1,
185 two,
186 3,
187 });
188 foo2(true, [_]i32{
189 1,
190 2,
191 3,
192 });
193 foo2(true, [_]i32{
194 1,
195 two,
196 3,
197 });
198 }
199 fn foo(x: []const i32) void {
200 expect(x[0] == 1);
201 expect(x[1] == 2);
202 expect(x[2] == 3);
203 }
204 fn foo2(trash: bool, x: []const i32) void {
205 expect(trash);
206 expect(x[0] == 1);
207 expect(x[1] == 2);
208 expect(x[2] == 3);
209 }
210 };
211 S.entry(2);
212 comptime S.entry(2);
213}179}
214180
215test "double nested array to const slice cast in array literal" {181//test "array literal as argument to function" {
216 const S = struct {182// const S = struct {
217 fn entry(two: i32) void {183// fn entry(two: i32) void {
218 const cases = [_][]const []const i32{184// foo([_]i32{
219 [_][]const i32{[_]i32{1}},185// 1,
220 [_][]const i32{[_]i32{ 2, 3 }},186// 2,
221 [_][]const i32{187// 3,
222 [_]i32{4},188// });
223 [_]i32{ 5, 6, 7 },189// foo([_]i32{
224 },190// 1,
225 };191// two,
226 check(cases);192// 3,
227193// });
228 const cases2 = [_][]const i32{194// foo2(true, [_]i32{
229 [_]i32{1},195// 1,
230 [_]i32{ two, 3 },196// 2,
231 };197// 3,
232 expect(cases2.len == 2);198// });
233 expect(cases2[0].len == 1);199// foo2(true, [_]i32{
234 expect(cases2[0][0] == 1);200// 1,
235 expect(cases2[1].len == 2);201// two,
236 expect(cases2[1][0] == 2);202// 3,
237 expect(cases2[1][1] == 3);203// });
238204// }
239 const cases3 = [_][]const []const i32{205// fn foo(x: []const i32) void {
240 [_][]const i32{[_]i32{1}},206// expect(x[0] == 1);
241 [_][]const i32{[_]i32{ two, 3 }},207// expect(x[1] == 2);
242 [_][]const i32{208// expect(x[2] == 3);
243 [_]i32{4},209// }
244 [_]i32{ 5, 6, 7 },210// fn foo2(trash: bool, x: []const i32) void {
245 },211// expect(trash);
246 };212// expect(x[0] == 1);
247 check(cases3);213// expect(x[1] == 2);
248 }214// expect(x[2] == 3);
249215// }
250 fn check(cases: []const []const []const i32) void {216// };
251 expect(cases.len == 3);217// S.entry(2);
252 expect(cases[0].len == 1);218// comptime S.entry(2);
253 expect(cases[0][0].len == 1);219//}
254 expect(cases[0][0][0] == 1);220
255 expect(cases[1].len == 1);221//test "double nested array to const slice cast in array literal" {
256 expect(cases[1][0].len == 2);222// const S = struct {
257 expect(cases[1][0][0] == 2);223// fn entry(two: i32) void {
258 expect(cases[1][0][1] == 3);224// const cases = [_][]const []const i32{
259 expect(cases[2].len == 2);225// [_][]const i32{[_]i32{1}},
260 expect(cases[2][0].len == 1);226// [_][]const i32{[_]i32{ 2, 3 }},
261 expect(cases[2][0][0] == 4);227// [_][]const i32{
262 expect(cases[2][1].len == 3);228// [_]i32{4},
263 expect(cases[2][1][0] == 5);229// [_]i32{ 5, 6, 7 },
264 expect(cases[2][1][1] == 6);230// },
265 expect(cases[2][1][2] == 7);231// };
266 }232// check(cases);
267 };233//
268 S.entry(2);234// const cases2 = [_][]const i32{
269 comptime S.entry(2);235// [_]i32{1},
270}236// [_]i32{ two, 3 },
237// };
238// expect(cases2.len == 2);
239// expect(cases2[0].len == 1);
240// expect(cases2[0][0] == 1);
241// expect(cases2[1].len == 2);
242// expect(cases2[1][0] == 2);
243// expect(cases2[1][1] == 3);
244//
245// const cases3 = [_][]const []const i32{
246// [_][]const i32{[_]i32{1}},
247// [_][]const i32{[_]i32{ two, 3 }},
248// [_][]const i32{
249// [_]i32{4},
250// [_]i32{ 5, 6, 7 },
251// },
252// };
253// check(cases3);
254// }
255//
256// fn check(cases: []const []const []const i32) void {
257// expect(cases.len == 3);
258// expect(cases[0].len == 1);
259// expect(cases[0][0].len == 1);
260// expect(cases[0][0][0] == 1);
261// expect(cases[1].len == 1);
262// expect(cases[1][0].len == 2);
263// expect(cases[1][0][0] == 2);
264// expect(cases[1][0][1] == 3);
265// expect(cases[2].len == 2);
266// expect(cases[2][0].len == 1);
267// expect(cases[2][0][0] == 4);
268// expect(cases[2][1].len == 3);
269// expect(cases[2][1][0] == 5);
270// expect(cases[2][1][1] == 6);
271// expect(cases[2][1][2] == 7);
272// }
273// };
274// S.entry(2);
275// comptime S.entry(2);
276//}