| author | |
| committer | |
| log | d71f339395f8a3a3c09bbb2d51e6f35cb5295d14 |
| tree | 1272c38ac11e5276ed5d0e94753b21ed9a6509ee |
| parent | d5b8172a82f5b301b518501958ca1db11d07bc38 |
| signature | Commit is signed but in an unrecognized format. |
2 files changed, 22 insertions(+), 4 deletions(-)
src/stage1/analyze.cpp+12-4| ... | @@ -3457,10 +3457,18 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { | ... | @@ -3457,10 +3457,18 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 3457 | } | 3457 | } |
| 3458 | 3458 | ||
| 3459 | static Error resolve_opaque_type(CodeGen *g, ZigType *opaque_type) { | 3459 | static Error resolve_opaque_type(CodeGen *g, ZigType *opaque_type) { |
| 3460 | opaque_type->abi_align = UINT32_MAX; | 3460 | Error err = ErrorNone; |
| 3461 | opaque_type->abi_size = SIZE_MAX; | 3461 | AstNode *container_node = opaque_type->data.opaque.decl_node; |
| 3462 | opaque_type->size_in_bits = SIZE_MAX; | 3462 | if (container_node != nullptr) { |
| 3463 | return ErrorNone; | 3463 | assert(container_node->type == NodeTypeContainerDecl); |
| 3464 | AstNodeContainerDecl *container_decl = &container_node->data.container_decl; | ||
| 3465 | for (int i = 0; i < container_decl->fields.length; i++) { | ||
| 3466 | AstNode *field_node = container_decl->fields.items[i]; | ||
| 3467 | add_node_error(g, field_node, buf_create_from_str("opaque types cannot have fields")); | ||
| 3468 | err = ErrorSemanticAnalyzeFail; | ||
| 3469 | } | ||
| 3470 | } | ||
| 3471 | return err; | ||
| 3464 | } | 3472 | } |
| 3465 | 3473 | ||
| 3466 | void append_namespace_qualification(CodeGen *g, Buf *buf, ZigType *container_type) { | 3474 | void append_namespace_qualification(CodeGen *g, Buf *buf, ZigType *container_type) { |
test/compile_errors.zig+10| ... | @@ -125,6 +125,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -125,6 +125,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 125 | "tmp.zig:15:23: error: enum field missing: 'arst'", | 125 | "tmp.zig:15:23: error: enum field missing: 'arst'", |
| 126 | "tmp.zig:27:24: note: referenced here", | 126 | "tmp.zig:27:24: note: referenced here", |
| 127 | }); | 127 | }); |
| 128 | |||
| 129 | cases.add("opaque type with field", | ||
| 130 | \\const Opaque = opaque { foo: i32 }; | ||
| 131 | \\export fn entry() void { | ||
| 132 | \\ const foo: ?*Opaque = null; | ||
| 133 | \\} | ||
| 134 | , &[_][]const u8{ | ||
| 135 | "tmp.zig:1:25: error: opaque types cannot have fields", | ||
| 136 | }); | ||
| 137 | |||
| 128 | cases.add("@Type(.Fn) with is_generic = true", | 138 | cases.add("@Type(.Fn) with is_generic = true", |
| 129 | \\const Foo = @Type(.{ | 139 | \\const Foo = @Type(.{ |
| 130 | \\ .Fn = .{ | 140 | \\ .Fn = .{ |