Skip to content

Commit

Permalink
AstGen: improve 'file cannot be a tuple' source location
Browse files Browse the repository at this point in the history
Instead of just reporting this on token 0, report it on the first
tuple-like field.
  • Loading branch information
mlugg committed Feb 25, 2025
1 parent 055969b commit 3fcb440
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lib/std/zig/AstGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5097,18 +5097,16 @@ 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", .{});
} else {
return tupleDecl(gz, scope, node, container_decl, layout, backing_int_node);
}
if (node == 0) {
return astgen.failNode(tuple_field_node, "file cannot be a tuple", .{});
} else {
return tupleDecl(gz, scope, node, container_decl, layout, backing_int_node);
}
}

Expand Down
7 changes: 7 additions & 0 deletions test/cases/compile_errors/file_level_tuple_with_decls.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const std = @import("std");

u8,

// error
//
// :3:1: error: file cannot be a tuple

0 comments on commit 3fcb440

Please sign in to comment.