authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-02-24 14:37:18+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-02-25 22:28:47+00:00
log3fcb4408a55f3d0fb27f69555c62da81b6e9339c
tree07fa531571e4b330c19457c878840376f3c68a89
parent055969b1015ec574b985a29f0b3af8a77fabff20

AstGen: improve 'file cannot be a tuple' source location

Instead of just reporting this on token 0, report it on the first tuple-like field.

2 files changed, 15 insertions(+), 10 deletions(-)

lib/std/zig/AstGen.zig+8-10
......@@ -5097,18 +5097,16 @@ fn structDeclInner(
50975097 const gpa = astgen.gpa;
50985098 const tree = astgen.tree;
50995099
5100 {
5101 const is_tuple = for (container_decl.ast.members) |member_node| {
5100 is_tuple: {
5101 const tuple_field_node = for (container_decl.ast.members) |member_node| {
51025102 const container_field = tree.fullContainerField(member_node) orelse continue;
5103 if (container_field.ast.tuple_like) break true;
5104 } else false;
5103 if (container_field.ast.tuple_like) break member_node;
5104 } else break :is_tuple;
51055105
5106 if (is_tuple) {
5107 if (node == 0) {
5108 return astgen.failTok(0, "file cannot be a tuple", .{});
5109 } else {
5110 return tupleDecl(gz, scope, node, container_decl, layout, backing_int_node);
5111 }
5106 if (node == 0) {
5107 return astgen.failNode(tuple_field_node, "file cannot be a tuple", .{});
5108 } else {
5109 return tupleDecl(gz, scope, node, container_decl, layout, backing_int_node);
51125110 }
51135111 }
51145112
test/cases/compile_errors/file_level_tuple_with_decls.zig created+7
......@@ -0,0 +1,7 @@
1const std = @import("std");
2
3u8,
4
5// error
6//
7// :3:1: error: file cannot be a tuple