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.
This commit is contained in:
mlugg 2025-02-24 14:37:18 +00:00 committed by Matthew Lugg
parent 055969b101
commit 3fcb4408a5
2 changed files with 15 additions and 10 deletions

View File

@ -5097,18 +5097,16 @@ fn structDeclInner(
const gpa = astgen.gpa; const gpa = astgen.gpa;
const tree = astgen.tree; const tree = astgen.tree;
{ is_tuple: {
const is_tuple = for (container_decl.ast.members) |member_node| { const tuple_field_node = for (container_decl.ast.members) |member_node| {
const container_field = tree.fullContainerField(member_node) orelse continue; const container_field = tree.fullContainerField(member_node) orelse continue;
if (container_field.ast.tuple_like) break true; if (container_field.ast.tuple_like) break member_node;
} else false; } else break :is_tuple;
if (is_tuple) { if (node == 0) {
if (node == 0) { return astgen.failNode(tuple_field_node, "file cannot be a tuple", .{});
return astgen.failTok(0, "file cannot be a tuple", .{}); } else {
} else { return tupleDecl(gz, scope, node, container_decl, layout, backing_int_node);
return tupleDecl(gz, scope, node, container_decl, layout, backing_int_node);
}
} }
} }

View File

@ -0,0 +1,7 @@
const std = @import("std");
u8,
// error
//
// :3:1: error: file cannot be a tuple