| author | |
| committer | |
| log | 583e698256a2a26f26738c983e319d76926ef048 |
| tree | fa3ac65a89e627f5c4b361282f8bf0f20dbc78d1 |
| parent | d404d8a3637bc30dffc736e5fa1a68b8af0e19cb |
| signature |
2 files changed, 13 insertions(+), 8 deletions(-)
src/Sema.zig+6| ... | ... | @@ -10188,9 +10188,15 @@ fn analyzeAs( |
| 10188 | 10188 | const dest_ty_tag = dest_ty.zigTypeTagOrPoison(mod) catch |err| switch (err) { |
| 10189 | 10189 | error.GenericPoison => return operand, |
| 10190 | 10190 | }; |
| 10191 | ||
| 10192 | if (dest_ty_tag == .Opaque) { | |
| 10193 | return sema.fail(block, src, "cannot cast to opaque type '{}'", .{dest_ty.fmt(pt)}); | |
| 10194 | } | |
| 10195 | ||
| 10191 | 10196 | if (dest_ty_tag == .NoReturn) { |
| 10192 | 10197 | return sema.fail(block, src, "cannot cast to noreturn", .{}); |
| 10193 | 10198 | } |
| 10199 | ||
| 10194 | 10200 | const is_ret = if (zir_dest_type.toIndex()) |ptr_index| |
| 10195 | 10201 | sema.code.instructions.items(.tag)[@intFromEnum(ptr_index)] == .ret_type |
| 10196 | 10202 | else |
test/cases/compile_errors/directly_embedding_opaque_type_in_struct_and_union.zig+7-8| ... | ... | @@ -15,14 +15,13 @@ export fn b() void { |
| 15 | 15 | _ = &bar; |
| 16 | 16 | } |
| 17 | 17 | export fn c() void { |
| 18 | const baz = &@as(O, undefined); | |
| 19 | const qux = .{baz.*}; | |
| 20 | _ = qux; | |
| 18 | const baz = @as(O, undefined); | |
| 19 | _ = baz; | |
| 21 | 20 | } |
| 22 | 21 | export fn d() void { |
| 23 | const baz = &@as(O, undefined); | |
| 24 | const qux = .{ .a = baz.* }; | |
| 25 | _ = qux; | |
| 22 | const ptr: *O = @ptrFromInt(0x1000); | |
| 23 | const x = .{ptr.*}; | |
| 24 | _ = x; | |
| 26 | 25 | } |
| 27 | 26 | |
| 28 | 27 | // error |
| ... | ... | @@ -33,7 +32,7 @@ export fn d() void { |
| 33 | 32 | // :1:11: note: opaque declared here |
| 34 | 33 | // :7:10: error: opaque types have unknown size and therefore cannot be directly embedded in unions |
| 35 | 34 | // :1:11: note: opaque declared here |
| 36 | // :19:22: error: cannot load opaque type 'tmp.O' | |
| 35 | // :18:24: error: cannot cast to opaque type 'tmp.O' | |
| 37 | 36 | // :1:11: note: opaque declared here |
| 38 | // :24:28: error: cannot load opaque type 'tmp.O' | |
| 37 | // :23:20: error: cannot load opaque type 'tmp.O' | |
| 39 | 38 | // :1:11: note: opaque declared here |