| author | |
| committer | |
| log | a3855477866bbe59b0583ca07170a981e7ca5839 |
| tree | 04804df2f7778cfce9c535c99d718c9871fe6eda |
| parent | c49ab049c590d51661654084062f9f067c73fda0 |
Closes #45083 files changed, 28 insertions(+), 4 deletions(-)
src/ir.cpp+12-2| ... | @@ -26677,9 +26677,19 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i | ... | @@ -26677,9 +26677,19 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i |
| 26677 | 26677 | ||
| 26678 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, | 26678 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 26679 | return_type, nullptr, true, true); | 26679 | return_type, nullptr, true, true); |
| 26680 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { | 26680 | |
| 26681 | return result_loc; | 26681 | if (result_loc != nullptr) { |
| 26682 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { | ||
| 26683 | return result_loc; | ||
| 26684 | } | ||
| 26685 | IrInstGen *dummy_value = ir_const(ira, &instruction->base.base, return_type); | ||
| 26686 | dummy_value->value->special = ConstValSpecialRuntime; | ||
| 26687 | IrInstGen *dummy_result = ir_implicit_cast2(ira, &instruction->base.base, | ||
| 26688 | dummy_value, result_loc->value->type->data.pointer.child_type); | ||
| 26689 | if (type_is_invalid(dummy_result->value->type)) | ||
| 26690 | return ira->codegen->invalid_inst_gen; | ||
| 26682 | } | 26691 | } |
| 26692 | |||
| 26683 | return ir_build_slice_gen(ira, &instruction->base.base, return_type, | 26693 | return ir_build_slice_gen(ira, &instruction->base.base, return_type, |
| 26684 | ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc); | 26694 | ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc); |
| 26685 | } | 26695 | } |
test/compile_errors.zig+12| ... | @@ -3,6 +3,18 @@ const builtin = @import("builtin"); | ... | @@ -3,6 +3,18 @@ const builtin = @import("builtin"); |
| 3 | const Target = @import("std").Target; | 3 | const Target = @import("std").Target; |
| 4 | 4 | ||
| 5 | pub fn addCases(cases: *tests.CompileErrorContext) void { | 5 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6 | cases.addTest("slice to pointer conversion mismatch", | ||
| 7 | \\pub fn bytesAsSlice(bytes: var) [*]align(1) const u16 { | ||
| 8 | \\ return @ptrCast([*]align(1) const u16, bytes.ptr)[0..1]; | ||
| 9 | \\} | ||
| 10 | \\test "bytesAsSlice" { | ||
| 11 | \\ const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF }; | ||
| 12 | \\ const slice = bytesAsSlice(bytes[0..]); | ||
| 13 | \\} | ||
| 14 | , &[_][]const u8{ | ||
| 15 | "tmp.zig:2:54: error: expected type '[*]align(1) const u16', found '[]align(1) const u16'", | ||
| 16 | }); | ||
| 17 | |||
| 6 | cases.addTest("access invalid @typeInfo decl", | 18 | cases.addTest("access invalid @typeInfo decl", |
| 7 | \\const A = B; | 19 | \\const A = B; |
| 8 | \\test "Crash" { | 20 | \\test "Crash" { |
test/tests.zig+4-2| ... | @@ -677,8 +677,10 @@ pub const StackTracesContext = struct { | ... | @@ -677,8 +677,10 @@ pub const StackTracesContext = struct { |
| 677 | const got: []const u8 = got_result: { | 677 | const got: []const u8 = got_result: { |
| 678 | var buf = try Buffer.initSize(b.allocator, 0); | 678 | var buf = try Buffer.initSize(b.allocator, 0); |
| 679 | defer buf.deinit(); | 679 | defer buf.deinit(); |
| 680 | var bytes = stderr.toSliceConst(); | 680 | const bytes = if (stderr.endsWith("\n")) |
| 681 | if (bytes.len != 0 and bytes[bytes.len - 1] == '\n') bytes = bytes[0 .. bytes.len - 1]; | 681 | stderr.toSliceConst()[0 .. stderr.len() - 1] |
| 682 | else | ||
| 683 | stderr.toSliceConst()[0..stderr.len()]; | ||
| 682 | var it = mem.separate(bytes, "\n"); | 684 | var it = mem.separate(bytes, "\n"); |
| 683 | process_lines: while (it.next()) |line| { | 685 | process_lines: while (it.next()) |line| { |
| 684 | if (line.len == 0) continue; | 686 | if (line.len == 0) continue; |