| author | |
| committer | |
| log | 5c15c5fc48fa61569eca7bcd49e1c819db2a90c9 |
| tree | c0095f46e83632ba5ac75fa1960efcd2ecfdcfe0 |
| parent | 2e2740716103784334348c491a0e4d84052c5734 |
| signature |
closes #12932 files changed, 15 insertions(+), 0 deletions(-)
src/ir.cpp+5| ... | @@ -19229,6 +19229,11 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice | ... | @@ -19229,6 +19229,11 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice |
| 19229 | return ira->codegen->builtin_types.entry_invalid; | 19229 | return ira->codegen->builtin_types.entry_invalid; |
| 19230 | 19230 | ||
| 19231 | parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index]; | 19231 | parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index]; |
| 19232 | if (parent_ptr->special == ConstValSpecialUndef) { | ||
| 19233 | ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined")); | ||
| 19234 | return ira->codegen->builtin_types.entry_invalid; | ||
| 19235 | } | ||
| 19236 | |||
| 19232 | ConstExprValue *len_val = &slice_ptr->data.x_struct.fields[slice_len_index]; | 19237 | ConstExprValue *len_val = &slice_ptr->data.x_struct.fields[slice_len_index]; |
| 19233 | 19238 | ||
| 19234 | switch (parent_ptr->data.x_ptr.special) { | 19239 | switch (parent_ptr->data.x_ptr.special) { |
test/compile_errors.zig+10| ... | @@ -1,6 +1,16 @@ | ... | @@ -1,6 +1,16 @@ |
| 1 | const tests = @import("tests.zig"); | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | ||
| 3 | pub fn addCases(cases: *tests.CompileErrorContext) void { | 3 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4 | cases.add( | ||
| 5 | "comptime slice of an undefined slice", | ||
| 6 | \\comptime { | ||
| 7 | \\ var a: []u8 = undefined; | ||
| 8 | \\ var b = a[0..10]; | ||
| 9 | \\} | ||
| 10 | , | ||
| 11 | ".tmp_source.zig:3:14: error: slice of undefined", | ||
| 12 | ); | ||
| 13 | |||
| 4 | cases.add( | 14 | cases.add( |
| 5 | "implicit cast const array to mutable slice", | 15 | "implicit cast const array to mutable slice", |
| 6 | \\export fn entry() void { | 16 | \\export fn entry() void { |