| author | |
| committer | |
| log | 3c27d9c25a836a3d28f05509a7a77cb33d428dbd |
| tree | 96030724b5b3298e8f734ada4199c7ef684fb9b4 |
| parent | 3199792ade2dfcb88f6668849c54352e51fc1ae0 |
| parent | b7aa289ae45eb281968a48f21d3ecaf1fb86d830 |
| signature |
added error for implicit cast from *const T to *[1]T.6 files changed, 45 insertions(+), 17 deletions(-)
src/ir.cpp+6-1| ... | ... | @@ -11090,6 +11090,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou |
| 11090 | 11090 | Error err; |
| 11091 | 11091 | if ((err = type_resolve(ira->codegen, target->value.type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 11092 | 11092 | return ira->codegen->invalid_instruction; |
| 11093 | assert((wanted_type->data.pointer.is_const && target->value.type->data.pointer.is_const) || !target->value.type->data.pointer.is_const); | |
| 11093 | 11094 | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value.type)); |
| 11094 | 11095 | ZigType *array_type = wanted_type->data.pointer.child_type; |
| 11095 | 11096 | assert(array_type->id == ZigTypeIdArray); |
| ... | ... | @@ -11651,7 +11652,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 11651 | 11652 | if (array_type->id == ZigTypeIdArray && array_type->data.array.len == 1 && |
| 11652 | 11653 | types_match_const_cast_only(ira, array_type->data.array.child_type, |
| 11653 | 11654 | actual_type->data.pointer.child_type, source_node, |
| 11654 | !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) | |
| 11655 | !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk && | |
| 11656 | // This should be the job of `types_match_const_cast_only` | |
| 11657 | // but `types_match_const_cast_only` only gets info for child_types | |
| 11658 | ((wanted_type->data.pointer.is_const && actual_type->data.pointer.is_const) || | |
| 11659 | !actual_type->data.pointer.is_const)) | |
| 11655 | 11660 | { |
| 11656 | 11661 | if ((err = type_resolve(ira->codegen, wanted_type->data.pointer.child_type, |
| 11657 | 11662 | ResolveStatusAlignmentKnown))) |
std/event/loop.zig+8-8| ... | ... | @@ -263,7 +263,7 @@ pub const Loop = struct { |
| 263 | 263 | .next = undefined, |
| 264 | 264 | }; |
| 265 | 265 | self.available_eventfd_resume_nodes.push(eventfd_node); |
| 266 | const kevent_array = (*[1]posix.Kevent)(&eventfd_node.data.kevent); | |
| 266 | const kevent_array = (*const [1]posix.Kevent)(&eventfd_node.data.kevent); | |
| 267 | 267 | _ = try os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null); |
| 268 | 268 | eventfd_node.data.kevent.flags = posix.EV_CLEAR | posix.EV_ENABLE; |
| 269 | 269 | eventfd_node.data.kevent.fflags = posix.NOTE_TRIGGER; |
| ... | ... | @@ -279,7 +279,7 @@ pub const Loop = struct { |
| 279 | 279 | .data = 0, |
| 280 | 280 | .udata = @ptrToInt(&self.final_resume_node), |
| 281 | 281 | }; |
| 282 | const final_kev_arr = (*[1]posix.Kevent)(&self.os_data.final_kevent); | |
| 282 | const final_kev_arr = (*const [1]posix.Kevent)(&self.os_data.final_kevent); | |
| 283 | 283 | _ = try os.bsdKEvent(self.os_data.kqfd, final_kev_arr, empty_kevs, null); |
| 284 | 284 | self.os_data.final_kevent.flags = posix.EV_ENABLE; |
| 285 | 285 | self.os_data.final_kevent.fflags = posix.NOTE_TRIGGER; |
| ... | ... | @@ -472,7 +472,7 @@ pub const Loop = struct { |
| 472 | 472 | .data = 0, |
| 473 | 473 | .udata = @ptrToInt(&resume_node.base), |
| 474 | 474 | }; |
| 475 | const kevent_array = (*[1]posix.Kevent)(&kev); | |
| 475 | const kevent_array = (*const [1]posix.Kevent)(&kev); | |
| 476 | 476 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; |
| 477 | 477 | _ = try os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null); |
| 478 | 478 | } |
| ... | ... | @@ -486,7 +486,7 @@ pub const Loop = struct { |
| 486 | 486 | .data = 0, |
| 487 | 487 | .udata = 0, |
| 488 | 488 | }; |
| 489 | const kevent_array = (*[1]posix.Kevent)(&kev); | |
| 489 | const kevent_array = (*const [1]posix.Kevent)(&kev); | |
| 490 | 490 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; |
| 491 | 491 | _ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch undefined; |
| 492 | 492 | self.finishOneEvent(); |
| ... | ... | @@ -502,7 +502,7 @@ pub const Loop = struct { |
| 502 | 502 | eventfd_node.base.handle = next_tick_node.data; |
| 503 | 503 | switch (builtin.os) { |
| 504 | 504 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 505 | const kevent_array = (*[1]posix.Kevent)(&eventfd_node.kevent); | |
| 505 | const kevent_array = (*const [1]posix.Kevent)(&eventfd_node.kevent); | |
| 506 | 506 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; |
| 507 | 507 | _ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch { |
| 508 | 508 | self.next_tick_queue.unget(next_tick_node); |
| ... | ... | @@ -631,7 +631,7 @@ pub const Loop = struct { |
| 631 | 631 | }, |
| 632 | 632 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 633 | 633 | self.posixFsRequest(&self.os_data.fs_end_request); |
| 634 | const final_kevent = (*[1]posix.Kevent)(&self.os_data.final_kevent); | |
| 634 | const final_kevent = (*const [1]posix.Kevent)(&self.os_data.final_kevent); | |
| 635 | 635 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; |
| 636 | 636 | // cannot fail because we already added it and this just enables it |
| 637 | 637 | _ = os.bsdKEvent(self.os_data.kqfd, final_kevent, empty_kevs, null) catch unreachable; |
| ... | ... | @@ -751,7 +751,7 @@ pub const Loop = struct { |
| 751 | 751 | self.os_data.fs_queue.put(request_node); |
| 752 | 752 | switch (builtin.os) { |
| 753 | 753 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 754 | const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wake); | |
| 754 | const fs_kevs = (*const [1]posix.Kevent)(&self.os_data.fs_kevent_wake); | |
| 755 | 755 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; |
| 756 | 756 | _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable; |
| 757 | 757 | }, |
| ... | ... | @@ -821,7 +821,7 @@ pub const Loop = struct { |
| 821 | 821 | } |
| 822 | 822 | }, |
| 823 | 823 | builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => { |
| 824 | const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wait); | |
| 824 | const fs_kevs = (*const [1]posix.Kevent)(&self.os_data.fs_kevent_wait); | |
| 825 | 825 | var out_kevs: [1]posix.Kevent = undefined; |
| 826 | 826 | _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable; |
| 827 | 827 | }, |
std/fmt.zig+5-5| ... | ... | @@ -375,7 +375,7 @@ pub fn formatAsciiChar( |
| 375 | 375 | comptime Errors: type, |
| 376 | 376 | output: fn (@typeOf(context), []const u8) Errors!void, |
| 377 | 377 | ) Errors!void { |
| 378 | return output(context, (*[1]u8)(&c)[0..]); | |
| 378 | return output(context, (*const [1]u8)(&c)[0..]); | |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | pub fn formatBuf( |
| ... | ... | @@ -390,7 +390,7 @@ pub fn formatBuf( |
| 390 | 390 | var leftover_padding = if (width > buf.len) (width - buf.len) else return; |
| 391 | 391 | const pad_byte: u8 = ' '; |
| 392 | 392 | while (leftover_padding > 0) : (leftover_padding -= 1) { |
| 393 | try output(context, (*[1]u8)(&pad_byte)[0..1]); | |
| 393 | try output(context, (*const [1]u8)(&pad_byte)[0..1]); | |
| 394 | 394 | } |
| 395 | 395 | } |
| 396 | 396 | |
| ... | ... | @@ -705,7 +705,7 @@ fn formatIntSigned( |
| 705 | 705 | const uint = @IntType(false, @typeOf(value).bit_count); |
| 706 | 706 | if (value < 0) { |
| 707 | 707 | const minus_sign: u8 = '-'; |
| 708 | try output(context, (*[1]u8)(&minus_sign)[0..]); | |
| 708 | try output(context, (*const [1]u8)(&minus_sign)[0..]); | |
| 709 | 709 | const new_value = @intCast(uint, -(value + 1)) + 1; |
| 710 | 710 | const new_width = if (width == 0) 0 else (width - 1); |
| 711 | 711 | return formatIntUnsigned(new_value, base, uppercase, new_width, context, Errors, output); |
| ... | ... | @@ -713,7 +713,7 @@ fn formatIntSigned( |
| 713 | 713 | return formatIntUnsigned(@intCast(uint, value), base, uppercase, width, context, Errors, output); |
| 714 | 714 | } else { |
| 715 | 715 | const plus_sign: u8 = '+'; |
| 716 | try output(context, (*[1]u8)(&plus_sign)[0..]); | |
| 716 | try output(context, (*const [1]u8)(&plus_sign)[0..]); | |
| 717 | 717 | const new_value = @intCast(uint, value); |
| 718 | 718 | const new_width = if (width == 0) 0 else (width - 1); |
| 719 | 719 | return formatIntUnsigned(new_value, base, uppercase, new_width, context, Errors, output); |
| ... | ... | @@ -751,7 +751,7 @@ fn formatIntUnsigned( |
| 751 | 751 | const zero_byte: u8 = '0'; |
| 752 | 752 | var leftover_padding = padding - index; |
| 753 | 753 | while (true) { |
| 754 | try output(context, (*[1]u8)(&zero_byte)[0..]); | |
| 754 | try output(context, (*const [1]u8)(&zero_byte)[0..]); | |
| 755 | 755 | leftover_padding -= 1; |
| 756 | 756 | if (leftover_padding == 0) break; |
| 757 | 757 | } |
std/io.zig+2-2| ... | ... | @@ -227,12 +227,12 @@ pub fn OutStream(comptime WriteError: type) type { |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | pub fn writeByte(self: *Self, byte: u8) Error!void { |
| 230 | const slice = (*[1]u8)(&byte)[0..]; | |
| 230 | const slice = (*const [1]u8)(&byte)[0..]; | |
| 231 | 231 | return self.writeFn(self, slice); |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | pub fn writeByteNTimes(self: *Self, byte: u8, n: usize) Error!void { |
| 235 | const slice = (*[1]u8)(&byte)[0..]; | |
| 235 | const slice = (*const [1]u8)(&byte)[0..]; | |
| 236 | 236 | var i: usize = 0; |
| 237 | 237 | while (i < n) : (i += 1) { |
| 238 | 238 | try self.writeFn(self, slice); |
test/compile_errors.zig+23| ... | ... | @@ -5869,4 +5869,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5869 | 5869 | \\ comptime testCompileLog(Bar{.X = 123}); |
| 5870 | 5870 | \\} |
| 5871 | 5871 | , "tmp.zig:6:5: error: found compile log statement"); |
| 5872 | ||
| 5873 | cases.add( | |
| 5874 | "attempted implicit cast from *const T to *[1]T", | |
| 5875 | \\export fn entry(byte: u8) void { | |
| 5876 | \\ const w: i32 = 1234; | |
| 5877 | \\ var x: *const i32 = &w; | |
| 5878 | \\ var y: *[1]i32 = x; | |
| 5879 | \\ y[0] += 1; | |
| 5880 | \\} | |
| 5881 | , | |
| 5882 | "tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32'", | |
| 5883 | "tmp.zig:4:22: note: pointer type child 'i32' cannot cast into pointer type child '[1]i32'", | |
| 5884 | ); | |
| 5885 | ||
| 5886 | cases.add( | |
| 5887 | "attempted implicit cast from *const T to []T", | |
| 5888 | \\export fn entry() void { | |
| 5889 | \\ const u: u32 = 42; | |
| 5890 | \\ const x: []u32 = &u; | |
| 5891 | \\} | |
| 5892 | , | |
| 5893 | "tmp.zig:3:23: error: expected type '[]u32', found '*const u32'", | |
| 5894 | ); | |
| 5872 | 5895 | } |
test/stage1/behavior/align.zig+1-1| ... | ... | @@ -60,7 +60,7 @@ fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 { |
| 60 | 60 | test "implicitly decreasing slice alignment" { |
| 61 | 61 | const a: u32 align(4) = 3; |
| 62 | 62 | const b: u32 align(8) = 4; |
| 63 | expect(addUnalignedSlice((*[1]u32)(&a)[0..], (*[1]u32)(&b)[0..]) == 7); | |
| 63 | expect(addUnalignedSlice((*const [1]u32)(&a)[0..], (*const [1]u32)(&b)[0..]) == 7); | |
| 64 | 64 | } |
| 65 | 65 | fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 { |
| 66 | 66 | return a[0] + b[0]; |