Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19168,8 +19168,8 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
if (inst_data.size != .one) {
return sema.fail(block, elem_ty_src, "function pointers must be single pointers", .{});
}
} else if (inst_data.size == .many and elem_ty.zigTypeTag(zcu) == .@"opaque") {
return sema.fail(block, elem_ty_src, "unknown-length pointer to opaque not allowed", .{});
} else if (inst_data.size != .one and elem_ty.zigTypeTag(zcu) == .@"opaque") {
return sema.fail(block, elem_ty_src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(pt)});
} else if (inst_data.size == .c) {
if (!try sema.validateExternType(elem_ty, .other)) {
const msg = msg: {
Expand All @@ -19183,9 +19183,6 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
};
return sema.failWithOwnedErrorMsg(block, msg);
}
if (elem_ty.zigTypeTag(zcu) == .@"opaque") {
return sema.fail(block, elem_ty_src, "C pointers cannot point to opaque types", .{});
}
}

if (host_size != 0 and !try sema.validatePackedType(elem_ty)) {
Expand Down Expand Up @@ -20674,8 +20671,8 @@ fn zirReify(
if (ptr_size != .one) {
return sema.fail(block, src, "function pointers must be single pointers", .{});
}
} else if (ptr_size == .many and elem_ty.zigTypeTag(zcu) == .@"opaque") {
return sema.fail(block, src, "unknown-length pointer to opaque not allowed", .{});
} else if (ptr_size != .one and elem_ty.zigTypeTag(zcu) == .@"opaque") {
return sema.fail(block, src, "indexable pointer to opaque type '{f}' not allowed", .{elem_ty.fmt(pt)});
} else if (ptr_size == .c) {
if (!try sema.validateExternType(elem_ty, .other)) {
const msg = msg: {
Expand All @@ -20689,9 +20686,6 @@ fn zirReify(
};
return sema.failWithOwnedErrorMsg(block, msg);
}
if (elem_ty.zigTypeTag(zcu) == .@"opaque") {
return sema.fail(block, src, "C pointers cannot point to opaque types", .{});
}
}

const ty = try pt.ptrTypeSema(.{
Expand Down
9 changes: 0 additions & 9 deletions test/cases/compile_errors/C_pointer_to_anyopaque.zig

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ pub export fn entry3() void {
const ptr: *const anyopaque = x;
_ = ptr;
}
export fn entry4() void {
var a: []*u32 = undefined;
_ = &a;
var b: []anyopaque = undefined;
b = a;
}

// error
//
Expand All @@ -31,5 +25,3 @@ export fn entry4() void {
// :11:12: note: parameter type declared here
// :15:35: error: expected type '*const anyopaque', found '*?*usize'
// :15:35: note: cannot implicitly cast double pointer '*?*usize' to anyopaque pointer '*const anyopaque'
// :22:9: error: expected type '[]anyopaque', found '[]*u32'
// :22:9: note: cannot implicitly cast double pointer '[]*u32' to anyopaque pointer '[]anyopaque'
55 changes: 55 additions & 0 deletions test/cases/compile_errors/invalid_pointer_to_opaque.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export fn a() void {
_ = []anyopaque;
}
export fn b() void {
_ = [*]anyopaque;
}
export fn c() void {
_ = [*c]anyopaque;
}

export fn d() void {
_ = @Type(.{ .pointer = .{
.size = .slice,
.is_const = false,
.is_volatile = false,
.alignment = 1,
.address_space = .generic,
.child = anyopaque,
.is_allowzero = false,
.sentinel_ptr = null,
} });
}
export fn e() void {
_ = @Type(.{ .pointer = .{
.size = .many,
.is_const = false,
.is_volatile = false,
.alignment = 1,
.address_space = .generic,
.child = anyopaque,
.is_allowzero = false,
.sentinel_ptr = null,
} });
}
export fn f() void {
_ = @Type(.{ .pointer = .{
.size = .c,
.is_const = false,
.is_volatile = false,
.alignment = 1,
.address_space = .generic,
.child = anyopaque,
.is_allowzero = false,
.sentinel_ptr = null,
} });
}

// error
//
// :2:11: error: indexable pointer to opaque type 'anyopaque' not allowed
// :5:12: error: indexable pointer to opaque type 'anyopaque' not allowed
// :8:13: error: indexable pointer to opaque type 'anyopaque' not allowed
// :12:9: error: indexable pointer to opaque type 'anyopaque' not allowed
// :24:9: error: indexable pointer to opaque type 'anyopaque' not allowed
// :36:9: error: indexable pointer to opaque type 'anyopaque' not allowed
10 changes: 0 additions & 10 deletions test/cases/compile_errors/pointer_to_anyopaque_slice.zig

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion test/cases/error_in_nested_declaration.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ pub export fn entry2() void {
//
// :6:20: error: cannot @bitCast to '[]i32'
// :6:20: note: use @ptrCast to cast from '[]u32'
// :17:12: error: C pointers cannot point to opaque types
// :17:12: error: indexable pointer to opaque type 'anyopaque' not allowed