Skip to content

Commit 071453d

Browse files
xdBronchmlugg
authored andcommitted
fix 'redundant comptime keyword' error source location and add tests
1 parent 181b25c commit 071453d

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/std/zig/AstGen.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
comptime {
2+
_ = comptime 0;
3+
}
4+
comptime {
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

0 commit comments

Comments
 (0)