authorgravatar for 51252236+xdBronch@users.noreply.github.comxdBronch <51252236+xdBronch@users.noreply.github.com> 2025-11-12 10:12:07-05:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-11-13 19:47:36+00:00
log071453d5b9a8a48211c4517185df1b41d42107c7
tree9f1fc96c50b4a5440d3c00c03a20966dc62ce7bf
parent181b25ce4fcebc32f6fdc7498148c0f5e131dda9

fix 'redundant comptime keyword' error source location and add tests


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

lib/std/zig/AstGen.zig+4-4
......@@ -2117,10 +2117,10 @@ fn comptimeExprAst(
21172117 node: Ast.Node.Index,
21182118) InnerError!Zir.Inst.Ref {
21192119 const astgen = gz.astgen;
2120 const tree = astgen.tree;
21202121 if (gz.is_comptime) {
2121 try astgen.appendErrorNode(node, "redundant comptime keyword in already comptime scope", .{});
2122 try astgen.appendErrorTok(tree.nodeMainToken(node), "redundant comptime keyword in already comptime scope", .{});
21222123 }
2123 const tree = astgen.tree;
21242124 const body_node = tree.nodeData(node).node;
21252125 return comptimeExpr2(gz, scope, ri, body_node, node, .comptime_keyword);
21262126}
......@@ -3469,7 +3469,7 @@ fn assignDestructure(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerErro
34693469
34703470 const full = tree.assignDestructure(node);
34713471 if (full.comptime_token != null and gz.is_comptime) {
3472 return astgen.appendErrorNode(node, "redundant comptime keyword in already comptime scope", .{});
3472 return astgen.appendErrorTok(full.comptime_token.?, "redundant comptime keyword in already comptime scope", .{});
34733473 }
34743474
34753475 // If this expression is marked comptime, we must wrap the whole thing in a comptime block.
......@@ -3525,7 +3525,7 @@ fn assignDestructureMaybeDecls(
35253525
35263526 const full = tree.assignDestructure(node);
35273527 if (full.comptime_token != null and gz.is_comptime) {
3528 try astgen.appendErrorNode(node, "redundant comptime keyword in already comptime scope", .{});
3528 try astgen.appendErrorTok(full.comptime_token.?, "redundant comptime keyword in already comptime scope", .{});
35293529 }
35303530
35313531 const is_comptime = full.comptime_token != null or gz.is_comptime;
test/cases/compile_errors/redundant_comptime_keyword.zig created+11
......@@ -0,0 +1,11 @@
1comptime {
2 _ = comptime 0;
3}
4comptime {
5 comptime _, _ = .{ 0, 0 };
6}
7
8// error
9//
10// :2:9: error: redundant comptime keyword in already comptime scope
11// :5:5: error: redundant comptime keyword in already comptime scope