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

View File

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