mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
fix 'redundant comptime keyword' error source location and add tests
This commit is contained in:
parent
181b25ce4f
commit
071453d5b9
2 changed files with 16 additions and 5 deletions
|
|
@ -2117,10 +2117,10 @@ fn comptimeExprAst(
|
|||
node: Ast.Node.Index,
|
||||
) InnerError!Zir.Inst.Ref {
|
||||
const astgen = gz.astgen;
|
||||
if (gz.is_comptime) {
|
||||
try astgen.appendErrorNode(node, "redundant comptime keyword in already comptime scope", .{});
|
||||
}
|
||||
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;
|
||||
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);
|
||||
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.
|
||||
|
|
@ -3525,7 +3525,7 @@ fn assignDestructureMaybeDecls(
|
|||
|
||||
const full = tree.assignDestructure(node);
|
||||
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;
|
||||
|
|
|
|||
11
test/cases/compile_errors/redundant_comptime_keyword.zig
Normal file
11
test/cases/compile_errors/redundant_comptime_keyword.zig
Normal 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
|
||||
Loading…
Add table
Reference in a new issue