mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
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:
parent
055969b101
commit
3fcb4408a5
@ -5097,20 +5097,18 @@ 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.failTok(0, "file cannot be a tuple", .{});
|
return astgen.failNode(tuple_field_node, "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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const decl_inst = try gz.reserveInstructionIndex();
|
const decl_inst = try gz.reserveInstructionIndex();
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,7 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
u8,
|
||||||
|
|
||||||
|
// error
|
||||||
|
//
|
||||||
|
// :3:1: error: file cannot be a tuple
|
||||||
Loading…
x
Reference in New Issue
Block a user