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

This commit is contained in:
xdBronch 2025-11-12 10:12:07 -05:00 committed by Matthew Lugg
parent 181b25ce4f
commit 071453d5b9
2 changed files with 16 additions and 5 deletions

View file

@ -2117,10 +2117,10 @@ fn comptimeExprAst(
node: Ast.Node.Index, node: Ast.Node.Index,
) InnerError!Zir.Inst.Ref { ) InnerError!Zir.Inst.Ref {
const astgen = gz.astgen; const astgen = gz.astgen;
if (gz.is_comptime) {
try astgen.appendErrorNode(node, "redundant comptime keyword in already comptime scope", .{});
}
const tree = astgen.tree; const tree = astgen.tree;
if (gz.is_comptime) {
try astgen.appendErrorTok(tree.nodeMainToken(node), "redundant comptime keyword in already comptime scope", .{});
}
const body_node = tree.nodeData(node).node; const body_node = tree.nodeData(node).node;
return comptimeExpr2(gz, scope, ri, body_node, node, .comptime_keyword); return comptimeExpr2(gz, scope, ri, body_node, node, .comptime_keyword);
} }
@ -3469,7 +3469,7 @@ fn assignDestructure(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerErro
const full = tree.assignDestructure(node); const full = tree.assignDestructure(node);
if (full.comptime_token != null and gz.is_comptime) { if (full.comptime_token != null and gz.is_comptime) {
return astgen.appendErrorNode(node, "redundant comptime keyword in already comptime scope", .{}); return astgen.appendErrorTok(full.comptime_token.?, "redundant comptime keyword in already comptime scope", .{});
} }
// If this expression is marked comptime, we must wrap the whole thing in a comptime block. // If this expression is marked comptime, we must wrap the whole thing in a comptime block.
@ -3525,7 +3525,7 @@ fn assignDestructureMaybeDecls(
const full = tree.assignDestructure(node); const full = tree.assignDestructure(node);
if (full.comptime_token != null and gz.is_comptime) { if (full.comptime_token != null and gz.is_comptime) {
try astgen.appendErrorNode(node, "redundant comptime keyword in already comptime scope", .{}); try astgen.appendErrorTok(full.comptime_token.?, "redundant comptime keyword in already comptime scope", .{});
} }
const is_comptime = full.comptime_token != null or gz.is_comptime; const is_comptime = full.comptime_token != null or gz.is_comptime;

View file

@ -0,0 +1,11 @@
comptime {
_ = comptime 0;
}
comptime {
comptime _, _ = .{ 0, 0 };
}
// error
//
// :2:9: error: redundant comptime keyword in already comptime scope
// :5:5: error: redundant comptime keyword in already comptime scope