authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2026-10-03 18:54:25-05:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-09 10:15:11+02:00
log09eb81de8b000a760680f42c07ef50cd30f97d08
tree2a7efa44107d0168d18a85c20fa49743d4e56cdd
parent18d9b2850ecba8fca14b11bd18111c17f0415aa9

AstGen: increment baseline when inside backing tag


2 files changed, 35 insertions(+), 0 deletions(-)

lib/std/zig/AstGen.zig+6
......@@ -4920,6 +4920,8 @@ fn structDeclInner(
49204920
49214921 // Before any field bodies comes the backing int type, if specified.
49224922 const backing_int_type_body_len: ?u32 = if (maybe_backing_int_node.unwrap()) |backing_int_node| len: {
4923 block_scope.src_baseline = backing_int_node;
4924 defer block_scope.src_baseline = node;
49234925 if (layout != .@"packed") return astgen.failNode(
49244926 backing_int_node,
49254927 "non-packed struct does not support backing integer type",
......@@ -5215,6 +5217,8 @@ fn unionDeclInner(
52155217
52165218 // Before any field bodies comes the tag/backing type, if specified.
52175219 const arg_type_body_len: ?u32 = if (opt_arg_node.unwrap()) |arg_node| len: {
5220 block_scope.src_baseline = arg_node;
5221 defer block_scope.src_baseline = node;
52185222 astgen.src_hasher.update(astgen.tree.getNodeSource(arg_node));
52195223 const type_ref = try typeExpr(&block_scope, &namespace.base, arg_node);
52205224 if (!block_scope.endsWithNoReturn()) {
......@@ -5435,6 +5439,8 @@ fn containerDecl(
54355439
54365440 // Before any field bodies comes the tag type, if specified.
54375441 const tag_type_body_len: ?u32 = if (container_decl.ast.arg.unwrap()) |tag_type_node| len: {
5442 block_scope.src_baseline = tag_type_node;
5443 defer block_scope.src_baseline = node;
54385444 astgen.src_hasher.update(astgen.tree.getNodeSource(tag_type_node));
54395445 const type_ref = try typeExpr(&block_scope, &namespace.base, tag_type_node);
54405446 if (!block_scope.endsWithNoReturn()) {
test/cases/compile_errors/compile_error_in_backing_tag.zig created+29
......@@ -0,0 +1,29 @@
1const E = enum(@compileError("enum")) {
2 x = 0,
3};
4
5const U = union(enum(@compileError("union"))) {
6 x = 0,
7};
8
9const S = packed struct(@compileError("struct")) {
10 x: u8 = 0,
11};
12
13comptime {
14 _ = &E.x;
15}
16
17comptime {
18 _ = &U.x;
19}
20
21comptime {
22 _ = &S{};
23}
24
25// error
26//
27// :1:16: error: enum
28// :5:22: error: union
29// :9:25: error: struct