| author | |
| committer | |
| log | 92f64899c110808a80c70d05e572bbd8e2448732 |
| tree | 55aac0928bd9e8e941bb8d75ed91e12536478795 |
| parent | 19af9fa488ba7ddf2e7fd8f2f06ab594f7e23f91 |
7 files changed, 60 insertions(+), 43 deletions(-)
src/Sema.zig+4-10| ... | ... | @@ -19168,8 +19168,8 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19168 | 19168 | if (inst_data.size != .one) { |
| 19169 | 19169 | return sema.fail(block, elem_ty_src, "function pointers must be single pointers", .{}); |
| 19170 | 19170 | } |
| 19171 | } else if (inst_data.size == .many and elem_ty.zigTypeTag(zcu) == .@"opaque") { | |
| 19172 | return sema.fail(block, elem_ty_src, "unknown-length pointer to opaque not allowed", .{}); | |
| 19171 | } else if (inst_data.size != .one and elem_ty.zigTypeTag(zcu) == .@"opaque") { | |
| 19172 | return sema.fail(block, elem_ty_src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(pt)}); | |
| 19173 | 19173 | } else if (inst_data.size == .c) { |
| 19174 | 19174 | if (!try sema.validateExternType(elem_ty, .other)) { |
| 19175 | 19175 | const msg = msg: { |
| ... | ... | @@ -19183,9 +19183,6 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19183 | 19183 | }; |
| 19184 | 19184 | return sema.failWithOwnedErrorMsg(block, msg); |
| 19185 | 19185 | } |
| 19186 | if (elem_ty.zigTypeTag(zcu) == .@"opaque") { | |
| 19187 | return sema.fail(block, elem_ty_src, "C pointers cannot point to opaque types", .{}); | |
| 19188 | } | |
| 19189 | 19186 | } |
| 19190 | 19187 | |
| 19191 | 19188 | if (host_size != 0 and !try sema.validatePackedType(elem_ty)) { |
| ... | ... | @@ -20674,8 +20671,8 @@ fn zirReify( |
| 20674 | 20671 | if (ptr_size != .one) { |
| 20675 | 20672 | return sema.fail(block, src, "function pointers must be single pointers", .{}); |
| 20676 | 20673 | } |
| 20677 | } else if (ptr_size == .many and elem_ty.zigTypeTag(zcu) == .@"opaque") { | |
| 20678 | return sema.fail(block, src, "unknown-length pointer to opaque not allowed", .{}); | |
| 20674 | } else if (ptr_size != .one and elem_ty.zigTypeTag(zcu) == .@"opaque") { | |
| 20675 | return sema.fail(block, src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(pt)}); | |
| 20679 | 20676 | } else if (ptr_size == .c) { |
| 20680 | 20677 | if (!try sema.validateExternType(elem_ty, .other)) { |
| 20681 | 20678 | const msg = msg: { |
| ... | ... | @@ -20689,9 +20686,6 @@ fn zirReify( |
| 20689 | 20686 | }; |
| 20690 | 20687 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20691 | 20688 | } |
| 20692 | if (elem_ty.zigTypeTag(zcu) == .@"opaque") { | |
| 20693 | return sema.fail(block, src, "C pointers cannot point to opaque types", .{}); | |
| 20694 | } | |
| 20695 | 20689 | } |
| 20696 | 20690 | |
| 20697 | 20691 | const ty = try pt.ptrTypeSema(.{ |
test/cases/compile_errors/C_pointer_to_anyopaque.zig deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | export fn a() void { | |
| 2 | var x: *anyopaque = undefined; | |
| 3 | var y: [*c]anyopaque = x; | |
| 4 | _ = .{ &x, &y }; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // | |
| 9 | // :3:16: error: C pointers cannot point to opaque types |
test/cases/compile_errors/double_pointer_to_anyopaque_pointer.zig-8| ... | ... | @@ -15,12 +15,6 @@ pub export fn entry3() void { |
| 15 | 15 | const ptr: *const anyopaque = x; |
| 16 | 16 | _ = ptr; |
| 17 | 17 | } |
| 18 | export fn entry4() void { | |
| 19 | var a: []*u32 = undefined; | |
| 20 | _ = &a; | |
| 21 | var b: []anyopaque = undefined; | |
| 22 | b = a; | |
| 23 | } | |
| 24 | 18 | |
| 25 | 19 | // error |
| 26 | 20 | // |
| ... | ... | @@ -31,5 +25,3 @@ export fn entry4() void { |
| 31 | 25 | // :11:12: note: parameter type declared here |
| 32 | 26 | // :15:35: error: expected type '*const anyopaque', found '*?*usize' |
| 33 | 27 | // :15:35: note: cannot implicitly cast double pointer '*?*usize' to anyopaque pointer '*const anyopaque' |
| 34 | // :22:9: error: expected type '[]anyopaque', found '[]*u32' | |
| 35 | // :22:9: note: cannot implicitly cast double pointer '[]*u32' to anyopaque pointer '[]anyopaque' |
test/cases/compile_errors/invalid_pointer_to_opaque.zig created+55| ... | ... | @@ -0,0 +1,55 @@ |
| 1 | export fn a() void { | |
| 2 | _ = []anyopaque; | |
| 3 | } | |
| 4 | export fn b() void { | |
| 5 | _ = [*]anyopaque; | |
| 6 | } | |
| 7 | export fn c() void { | |
| 8 | _ = [*c]anyopaque; | |
| 9 | } | |
| 10 | ||
| 11 | export fn d() void { | |
| 12 | _ = @Type(.{ .pointer = .{ | |
| 13 | .size = .slice, | |
| 14 | .is_const = false, | |
| 15 | .is_volatile = false, | |
| 16 | .alignment = 1, | |
| 17 | .address_space = .generic, | |
| 18 | .child = anyopaque, | |
| 19 | .is_allowzero = false, | |
| 20 | .sentinel_ptr = null, | |
| 21 | } }); | |
| 22 | } | |
| 23 | export fn e() void { | |
| 24 | _ = @Type(.{ .pointer = .{ | |
| 25 | .size = .many, | |
| 26 | .is_const = false, | |
| 27 | .is_volatile = false, | |
| 28 | .alignment = 1, | |
| 29 | .address_space = .generic, | |
| 30 | .child = anyopaque, | |
| 31 | .is_allowzero = false, | |
| 32 | .sentinel_ptr = null, | |
| 33 | } }); | |
| 34 | } | |
| 35 | export fn f() void { | |
| 36 | _ = @Type(.{ .pointer = .{ | |
| 37 | .size = .c, | |
| 38 | .is_const = false, | |
| 39 | .is_volatile = false, | |
| 40 | .alignment = 1, | |
| 41 | .address_space = .generic, | |
| 42 | .child = anyopaque, | |
| 43 | .is_allowzero = false, | |
| 44 | .sentinel_ptr = null, | |
| 45 | } }); | |
| 46 | } | |
| 47 | ||
| 48 | // error | |
| 49 | // | |
| 50 | // :2:11: error: indexable pointer to opaque type 'anyopaque' not allowed | |
| 51 | // :5:12: error: indexable pointer to opaque type 'anyopaque' not allowed | |
| 52 | // :8:13: error: indexable pointer to opaque type 'anyopaque' not allowed | |
| 53 | // :12:9: error: indexable pointer to opaque type 'anyopaque' not allowed | |
| 54 | // :24:9: error: indexable pointer to opaque type 'anyopaque' not allowed | |
| 55 | // :36:9: error: indexable pointer to opaque type 'anyopaque' not allowed |
test/cases/compile_errors/pointer_to_anyopaque_slice.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | export fn x() void { | |
| 2 | var a: *u32 = undefined; | |
| 3 | var b: []anyopaque = undefined; | |
| 4 | b = a; | |
| 5 | _ = &a; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // | |
| 10 | // :4:9: error: expected type '[]anyopaque', found '*u32' |
test/cases/compile_errors/unknown_length_pointer_to_opaque.zig deleted-5| ... | ... | @@ -1,5 +0,0 @@ |
| 1 | export const T = [*]opaque {}; | |
| 2 | ||
| 3 | // error | |
| 4 | // | |
| 5 | // :1:21: error: unknown-length pointer to opaque not allowed |
test/cases/error_in_nested_declaration.zig+1-1| ... | ... | @@ -27,4 +27,4 @@ pub export fn entry2() void { |
| 27 | 27 | // |
| 28 | 28 | // :6:20: error: cannot @bitCast to '[]i32' |
| 29 | 29 | // :6:20: note: use @ptrCast to cast from '[]u32' |
| 30 | // :17:12: error: C pointers cannot point to opaque types | |
| 30 | // :17:12: error: indexable pointer to opaque type 'anyopaque' not allowed |