authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-20 12:40:11-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-20 12:40:11-05:00
log3d53a95718bbf7abd17cf69c623aff4e9a97a0b4
treeead092735b3f110f9b0ff9dcdaab262266fc08b3
parentc49ab049c590d51661654084062f9f067c73fda0
parentec889d5888c57d0337a1e00398d71241a9716ebe
signature Commit is signed but in an unrecognized format.

Merge branch 'LemonBoy-fix-4508'


4 files changed, 29 insertions(+), 4 deletions(-)

lib/std/fs.zig+1
......@@ -864,6 +864,7 @@ pub const Dir = struct {
864864 .OBJECT_NAME_INVALID => unreachable,
865865 .OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
866866 .OBJECT_PATH_NOT_FOUND => return error.FileNotFound,
867 .NO_MEDIA_IN_DEVICE => return error.NoDevice,
867868 .INVALID_PARAMETER => unreachable,
868869 .SHARING_VIOLATION => return error.SharingViolation,
869870 .ACCESS_DENIED => return error.AccessDenied,
src/ir.cpp+12-2
......@@ -26677,9 +26677,19 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i
2667726677
2667826678 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
2667926679 return_type, nullptr, true, true);
26680 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
26681 return result_loc;
26680
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;
2668226691 }
26692
2668326693 return ir_build_slice_gen(ira, &instruction->base.base, return_type,
2668426694 ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc);
2668526695}
test/compile_errors.zig+12
......@@ -3,6 +3,18 @@ const builtin = @import("builtin");
33const Target = @import("std").Target;
44
55pub 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
618 cases.addTest("access invalid @typeInfo decl",
719 \\const A = B;
820 \\test "Crash" {
test/tests.zig+4-2
......@@ -677,8 +677,10 @@ pub const StackTracesContext = struct {
677677 const got: []const u8 = got_result: {
678678 var buf = try Buffer.initSize(b.allocator, 0);
679679 defer buf.deinit();
680 var bytes = stderr.toSliceConst();
681 if (bytes.len != 0 and bytes[bytes.len - 1] == '\n') bytes = bytes[0 .. bytes.len - 1];
680 const bytes = if (stderr.endsWith("\n"))
681 stderr.toSliceConst()[0 .. stderr.len() - 1]
682 else
683 stderr.toSliceConst()[0..stderr.len()];
682684 var it = mem.separate(bytes, "\n");
683685 process_lines: while (it.next()) |line| {
684686 if (line.len == 0) continue;