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(...@@ -4920,6 +4920,8 @@ fn structDeclInner(
49204920
4921 // Before any field bodies comes the backing int type, if specified.4921 // Before any field bodies comes the backing int type, if specified.
4922 const backing_int_type_body_len: ?u32 = if (maybe_backing_int_node.unwrap()) |backing_int_node| len: {4922 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;
4923 if (layout != .@"packed") return astgen.failNode(4925 if (layout != .@"packed") return astgen.failNode(
4924 backing_int_node,4926 backing_int_node,
4925 "non-packed struct does not support backing integer type",4927 "non-packed struct does not support backing integer type",
...@@ -5215,6 +5217,8 @@ fn unionDeclInner(...@@ -5215,6 +5217,8 @@ fn unionDeclInner(
52155217
5216 // Before any field bodies comes the tag/backing type, if specified.5218 // Before any field bodies comes the tag/backing type, if specified.
5217 const arg_type_body_len: ?u32 = if (opt_arg_node.unwrap()) |arg_node| len: {5219 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;
5218 astgen.src_hasher.update(astgen.tree.getNodeSource(arg_node));5222 astgen.src_hasher.update(astgen.tree.getNodeSource(arg_node));
5219 const type_ref = try typeExpr(&block_scope, &namespace.base, arg_node);5223 const type_ref = try typeExpr(&block_scope, &namespace.base, arg_node);
5220 if (!block_scope.endsWithNoReturn()) {5224 if (!block_scope.endsWithNoReturn()) {
...@@ -5435,6 +5439,8 @@ fn containerDecl(...@@ -5435,6 +5439,8 @@ fn containerDecl(
54355439
5436 // Before any field bodies comes the tag type, if specified.5440 // Before any field bodies comes the tag type, if specified.
5437 const tag_type_body_len: ?u32 = if (container_decl.ast.arg.unwrap()) |tag_type_node| len: {5441 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;
5438 astgen.src_hasher.update(astgen.tree.getNodeSource(tag_type_node));5444 astgen.src_hasher.update(astgen.tree.getNodeSource(tag_type_node));
5439 const type_ref = try typeExpr(&block_scope, &namespace.base, tag_type_node);5445 const type_ref = try typeExpr(&block_scope, &namespace.base, tag_type_node);
5440 if (!block_scope.endsWithNoReturn()) {5446 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