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
signaturelock-open 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 {...@@ -864,6 +864,7 @@ pub const Dir = struct {
864 .OBJECT_NAME_INVALID => unreachable,864 .OBJECT_NAME_INVALID => unreachable,
865 .OBJECT_NAME_NOT_FOUND => return error.FileNotFound,865 .OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
866 .OBJECT_PATH_NOT_FOUND => return error.FileNotFound,866 .OBJECT_PATH_NOT_FOUND => return error.FileNotFound,
867 .NO_MEDIA_IN_DEVICE => return error.NoDevice,
867 .INVALID_PARAMETER => unreachable,868 .INVALID_PARAMETER => unreachable,
868 .SHARING_VIOLATION => return error.SharingViolation,869 .SHARING_VIOLATION => return error.SharingViolation,
869 .ACCESS_DENIED => return error.AccessDenied,870 .ACCESS_DENIED => return error.AccessDenied,
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
2667726677
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");
3const Target = @import("std").Target;3const Target = @import("std").Target;
44
5pub fn addCases(cases: *tests.CompileErrorContext) void {5pub 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;