diff options
| author | xdBronch <51252236+xdBronch@users.noreply.github.com> | 2025-10-27 19:41:32 -0400 |
|---|---|---|
| committer | Matthew Lugg <mlugg@mlugg.co.uk> | 2025-11-07 12:12:32 +0000 |
| commit | 92f64899c110808a80c70d05e572bbd8e2448732 (patch) | |
| tree | 55aac0928bd9e8e941bb8d75ed91e12536478795 /src/Sema.zig | |
| parent | 19af9fa488ba7ddf2e7fd8f2f06ab594f7e23f91 (diff) | |
| download | zig-92f64899c110808a80c70d05e572bbd8e2448732.tar.gz zig-92f64899c110808a80c70d05e572bbd8e2448732.zip | |
sema: disallow slices of opaque types
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 4016041d82..0b303d9ad7 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -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: { @@ -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)) { @@ -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: { @@ -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(.{ |
