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(...@@ -2117,10 +2117,10 @@ fn comptimeExprAst(
2117 node: Ast.Node.Index,2117 node: Ast.Node.Index,
2118) InnerError!Zir.Inst.Ref {2118) InnerError!Zir.Inst.Ref {
2119 const astgen = gz.astgen;2119 const astgen = gz.astgen;
2120 const tree = astgen.tree;
2120 if (gz.is_comptime) {2121 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", .{});
2122 }2123 }
2123 const tree = astgen.tree;
2124 const body_node = tree.nodeData(node).node;2124 const body_node = tree.nodeData(node).node;
2125 return comptimeExpr2(gz, scope, ri, body_node, node, .comptime_keyword);2125 return comptimeExpr2(gz, scope, ri, body_node, node, .comptime_keyword);
2126}2126}
...@@ -3469,7 +3469,7 @@ fn assignDestructure(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerErro...@@ -3469,7 +3469,7 @@ fn assignDestructure(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerErro
34693469
3470 const full = tree.assignDestructure(node);3470 const full = tree.assignDestructure(node);
3471 if (full.comptime_token != null and gz.is_comptime) {3471 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", .{});
3473 }3473 }
34743474
3475 // If this expression is marked comptime, we must wrap the whole thing in a comptime block.3475 // If this expression is marked comptime, we must wrap the whole thing in a comptime block.
...@@ -3525,7 +3525,7 @@ fn assignDestructureMaybeDecls(...@@ -3525,7 +3525,7 @@ fn assignDestructureMaybeDecls(
35253525
3526 const full = tree.assignDestructure(node);3526 const full = tree.assignDestructure(node);
3527 if (full.comptime_token != null and gz.is_comptime) {3527 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", .{});
3529 }3529 }
35303530
3531 const is_comptime = full.comptime_token != null or gz.is_comptime;3531 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