| author | |
| committer | |
| log | 428a2fdedd1d2d9ce6c7a3b28a379e4484468b9c |
| tree | ba01c1cdb18bed90ee9ffe3ac350a2307e1aa6cc |
| parent | e1b258f39fcb4fff97a4fcf6ee9db10bb71646cc |
| signature |
closes #19952 files changed, 26 insertions(+), 0 deletions(-)
src/analyze.cpp+8| ... | ... | @@ -1977,6 +1977,10 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) { |
| 1977 | 1977 | field->align = field->type_entry->abi_align; |
| 1978 | 1978 | } else { |
| 1979 | 1979 | if ((err = type_val_resolve_abi_align(g, field->type_val, &field->align))) { |
| 1980 | if (g->trace_err != nullptr) { | |
| 1981 | g->trace_err = add_error_note(g, g->trace_err, field->decl_node, | |
| 1982 | buf_create_from_str("while checking this field")); | |
| 1983 | } | |
| 1980 | 1984 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 1981 | 1985 | return err; |
| 1982 | 1986 | } |
| ... | ... | @@ -2497,6 +2501,10 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) { |
| 2497 | 2501 | field->align = 1; |
| 2498 | 2502 | } else { |
| 2499 | 2503 | if ((err = type_val_resolve_abi_align(g, field->type_val, &field->align))) { |
| 2504 | if (g->trace_err != nullptr) { | |
| 2505 | g->trace_err = add_error_note(g, g->trace_err, field->decl_node, | |
| 2506 | buf_create_from_str("while checking this field")); | |
| 2507 | } | |
| 2500 | 2508 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; |
| 2501 | 2509 | return err; |
| 2502 | 2510 | } |
test/compile_errors.zig+18| ... | ... | @@ -2,6 +2,24 @@ const tests = @import("tests.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | |
| 4 | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.add( | |
| 6 | "struct depends on itself via optional field", | |
| 7 | \\const LhsExpr = struct { | |
| 8 | \\ rhsExpr: ?AstObject, | |
| 9 | \\}; | |
| 10 | \\const AstObject = union { | |
| 11 | \\ lhsExpr: LhsExpr, | |
| 12 | \\}; | |
| 13 | \\export fn entry() void { | |
| 14 | \\ const lhsExpr = LhsExpr{ .rhsExpr = null }; | |
| 15 | \\ const obj = AstObject{ .lhsExpr = lhsExpr }; | |
| 16 | \\} | |
| 17 | , | |
| 18 | "tmp.zig:1:17: error: struct 'LhsExpr' depends on itself", | |
| 19 | "tmp.zig:5:5: note: while checking this field", | |
| 20 | "tmp.zig:2:5: note: while checking this field", | |
| 21 | ); | |
| 22 | ||
| 5 | 23 | cases.add( |
| 6 | 24 | "alignment of enum field specified", |
| 7 | 25 | \\const Number = enum { |