| author | |
| committer | |
| log | ec6ffaa1e47388a59035277dafbe3d9999a80fca |
| tree | 1680beba27c825cb980bce9b53a545e727b75627 |
| parent | 1b432072b5ae6a70a00464b48b7ebf8610293fc3 |
3 files changed, 20 insertions(+), 1 deletions(-)
src/Sema.zig+2-1| ... | @@ -25335,7 +25335,7 @@ fn coerceExtra( | ... | @@ -25335,7 +25335,7 @@ fn coerceExtra( |
| 25335 | 25335 | ||
| 25336 | // cast from *T and [*]T to *anyopaque | 25336 | // cast from *T and [*]T to *anyopaque |
| 25337 | // but don't do it if the source type is a double pointer | 25337 | // but don't do it if the source type is a double pointer |
| 25338 | if (dest_info.pointee_type.tag() == .anyopaque and inst_ty.zigTypeTag() == .Pointer) { | 25338 | if (dest_info.pointee_type.tag() == .anyopaque and inst_ty.zigTypeTag() == .Pointer) to_anyopaque: { |
| 25339 | if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :pointer; | 25339 | if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :pointer; |
| 25340 | const elem_ty = inst_ty.elemType2(); | 25340 | const elem_ty = inst_ty.elemType2(); |
| 25341 | if (elem_ty.zigTypeTag() == .Pointer or elem_ty.isPtrLikeOptional()) { | 25341 | if (elem_ty.zigTypeTag() == .Pointer or elem_ty.isPtrLikeOptional()) { |
| ... | @@ -25345,6 +25345,7 @@ fn coerceExtra( | ... | @@ -25345,6 +25345,7 @@ fn coerceExtra( |
| 25345 | } }; | 25345 | } }; |
| 25346 | break :pointer; | 25346 | break :pointer; |
| 25347 | } | 25347 | } |
| 25348 | if (dest_ty.isSlice()) break :to_anyopaque; | ||
| 25348 | if (inst_ty.isSlice()) { | 25349 | if (inst_ty.isSlice()) { |
| 25349 | in_memory_result = .{ .slice_to_anyopaque = .{ | 25350 | in_memory_result = .{ .slice_to_anyopaque = .{ |
| 25350 | .actual = inst_ty, | 25351 | .actual = inst_ty, |
test/cases/compile_errors/double_pointer_to_anyopaque_pointer.zig+7| ... | @@ -15,6 +15,11 @@ pub export fn entry3() void { | ... | @@ -15,6 +15,11 @@ pub export fn entry3() void { |
| 15 | const ptr: *const anyopaque = x; | 15 | const ptr: *const anyopaque = x; |
| 16 | _ = ptr; | 16 | _ = ptr; |
| 17 | } | 17 | } |
| 18 | export fn entry4() void { | ||
| 19 | var a: []*u32 = undefined; | ||
| 20 | var b: []anyopaque = undefined; | ||
| 21 | b = a; | ||
| 22 | } | ||
| 18 | 23 | ||
| 19 | // error | 24 | // error |
| 20 | // backend=stage2 | 25 | // backend=stage2 |
| ... | @@ -27,3 +32,5 @@ pub export fn entry3() void { | ... | @@ -27,3 +32,5 @@ pub export fn entry3() void { |
| 27 | // :11:12: note: parameter type declared here | 32 | // :11:12: note: parameter type declared here |
| 28 | // :15:35: error: expected type '*const anyopaque', found '*?*usize' | 33 | // :15:35: error: expected type '*const anyopaque', found '*?*usize' |
| 29 | // :15:35: note: cannot implicitly cast double pointer '*?*usize' to anyopaque pointer '*const anyopaque' | 34 | // :15:35: note: cannot implicitly cast double pointer '*?*usize' to anyopaque pointer '*const anyopaque' |
| 35 | // :21:9: error: expected type '[]anyopaque', found '[]*u32' | ||
| 36 | // :21:9: note: cannot implicitly cast double pointer '[]*u32' to anyopaque pointer '[]anyopaque' |
test/cases/compile_errors/pointer_to_anyopaque_slice.zig created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | export fn x() void { | ||
| 2 | var a: *u32 = undefined; | ||
| 3 | var b: []anyopaque = undefined; | ||
| 4 | b = a; | ||
| 5 | } | ||
| 6 | |||
| 7 | // error | ||
| 8 | // backend=stage2 | ||
| 9 | // target=native | ||
| 10 | // | ||
| 11 | // :4:9: error: expected type '[]anyopaque', found '*u32' | ||