| author | |
| committer | |
| log | 2a62d4b20be9b99f53367e74434e1971ced78848 |
| tree | dcff5a330112ddd1fe5f7adc806923f8fe65ccde |
| parent | 996a2284dde16b030a63cb9ba42f586c7a1b66cd |
Fixes #66932 files changed, 14 insertions(+), 1 deletions(-)
src/stage1/ir.cpp+4| ... | ... | @@ -22188,6 +22188,8 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 22188 | 22188 | } |
| 22189 | 22189 | return result; |
| 22190 | 22190 | } else if (is_slice(array_type)) { |
| 22191 | expand_undef_struct(ira->codegen, array_ptr_val); | |
| 22192 | ||
| 22191 | 22193 | ZigValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index]; |
| 22192 | 22194 | ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base.base); |
| 22193 | 22195 | if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| ... | ... | @@ -22252,6 +22254,8 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 22252 | 22254 | } |
| 22253 | 22255 | return result; |
| 22254 | 22256 | } else if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) { |
| 22257 | expand_undef_array(ira->codegen, array_ptr_val); | |
| 22258 | ||
| 22255 | 22259 | IrInstGen *result; |
| 22256 | 22260 | if (orig_array_ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 22257 | 22261 | result = ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope, |
test/compile_errors.zig+10-1| ... | ... | @@ -2,6 +2,15 @@ const tests = @import("tests.zig"); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | |
| 4 | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.add("indexing a undefined slice at comptime", | |
| 6 | \\comptime { | |
| 7 | \\ var slice: []u8 = undefined; | |
| 8 | \\ slice[0] = 2; | |
| 9 | \\} | |
| 10 | , &[_][]const u8{ | |
| 11 | "tmp.zig:3:10: error: index 0 outside slice of size 0", | |
| 12 | }); | |
| 13 | ||
| 5 | 14 | cases.add("array in c exported function", |
| 6 | 15 | \\export fn zig_array(x: [10]u8) void { |
| 7 | 16 | \\ expect(std.mem.eql(u8, &x, "1234567890")); |
| ... | ... | @@ -7714,7 +7723,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7714 | 7723 | }); |
| 7715 | 7724 | |
| 7716 | 7725 | cases.add( // fixed bug #2032 |
| 7717 | "compile diagnostic string for top level decl type", | |
| 7726 | "compile diagnostic string for top level decl type", | |
| 7718 | 7727 | \\export fn entry() void { |
| 7719 | 7728 | \\ var foo: u32 = @This(){}; |
| 7720 | 7729 | \\} |