From 09eb81de8b000a760680f42c07ef50cd30f97d08 Mon Sep 17 00:00:00 2001 From: David Rubin Date: Sat, 3 Oct 2026 18:54:25 -0500 Subject: [PATCH] AstGen: increment baseline when inside backing tag --- lib/std/zig/AstGen.zig | 6 ++++ .../compile_error_in_backing_tag.zig | 29 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/cases/compile_errors/compile_error_in_backing_tag.zig diff --git a/lib/std/zig/AstGen.zig b/lib/std/zig/AstGen.zig index 0b98fcf2b92d6b3f80e187f54f8060343fd8e24e..7e47a3e06d9d888b9680c3d2b3f6842543a114d0 100644 --- a/lib/std/zig/AstGen.zig +++ b/lib/std/zig/AstGen.zig @@ -4920,6 +4920,8 @@ fn structDeclInner( // Before any field bodies comes the backing int type, if specified. const backing_int_type_body_len: ?u32 = if (maybe_backing_int_node.unwrap()) |backing_int_node| len: { + block_scope.src_baseline = backing_int_node; + defer block_scope.src_baseline = node; if (layout != .@"packed") return astgen.failNode( backing_int_node, "non-packed struct does not support backing integer type", @@ -5215,6 +5217,8 @@ fn unionDeclInner( // Before any field bodies comes the tag/backing type, if specified. const arg_type_body_len: ?u32 = if (opt_arg_node.unwrap()) |arg_node| len: { + block_scope.src_baseline = arg_node; + defer block_scope.src_baseline = node; astgen.src_hasher.update(astgen.tree.getNodeSource(arg_node)); const type_ref = try typeExpr(&block_scope, &namespace.base, arg_node); if (!block_scope.endsWithNoReturn()) { @@ -5435,6 +5439,8 @@ fn containerDecl( // Before any field bodies comes the tag type, if specified. const tag_type_body_len: ?u32 = if (container_decl.ast.arg.unwrap()) |tag_type_node| len: { + block_scope.src_baseline = tag_type_node; + defer block_scope.src_baseline = node; astgen.src_hasher.update(astgen.tree.getNodeSource(tag_type_node)); const type_ref = try typeExpr(&block_scope, &namespace.base, tag_type_node); if (!block_scope.endsWithNoReturn()) { diff --git a/test/cases/compile_errors/compile_error_in_backing_tag.zig b/test/cases/compile_errors/compile_error_in_backing_tag.zig new file mode 100644 index 0000000000000000000000000000000000000000..1ff9a2f0dbce5822382faa9b585dbdd444e83113 --- /dev/null +++ b/test/cases/compile_errors/compile_error_in_backing_tag.zig @@ -0,0 +1,29 @@ +const E = enum(@compileError("enum")) { + x = 0, +}; + +const U = union(enum(@compileError("union"))) { + x = 0, +}; + +const S = packed struct(@compileError("struct")) { + x: u8 = 0, +}; + +comptime { + _ = &E.x; +} + +comptime { + _ = &U.x; +} + +comptime { + _ = &S{}; +} + +// error +// +// :1:16: error: enum +// :5:22: error: union +// :9:25: error: struct -- 2.54.0