authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-03-26 15:13:51+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-03-26 15:14:03+03:00
log4a5628e7306a242ce0d2f14f09eaf17ad4ae87b2
tree9b862cb1efa33705e150c306e6a40b1c7c9dd08a
parent3a7fe0d0105ed69354960896a5d9eadd9dee3563

Module: fix lazy srcloc resolution for new for loop syntax

Closes #15081

2 files changed, 23 insertions(+), 9 deletions(-)

src/Module.zig+9-9
......@@ -2459,7 +2459,7 @@ pub const SrcLoc = struct {
24592459 return nodeToSpan(tree, node_datas[asm_output].lhs);
24602460 },
24612461
2462 .node_offset_for_cond, .node_offset_if_cond => |node_off| {
2462 .node_offset_if_cond => |node_off| {
24632463 const tree = try src_loc.file_scope.getTree(gpa);
24642464 const node = src_loc.declRelativeToNodeIndex(node_off);
24652465 const node_tags = tree.nodes.items(.tag);
......@@ -2471,9 +2471,16 @@ pub const SrcLoc = struct {
24712471 .while_simple,
24722472 .while_cont,
24732473 .@"while",
2474 => tree.fullWhile(node).?.ast.cond_expr,
2475
24742476 .for_simple,
24752477 .@"for",
2476 => tree.fullWhile(node).?.ast.cond_expr,
2478 => {
2479 const inputs = tree.fullFor(node).?.ast.inputs;
2480 const start = tree.firstToken(inputs[0]);
2481 const end = tree.lastToken(inputs[inputs.len - 1]);
2482 return tokensToSpan(tree, start, end, start);
2483 },
24772484
24782485 .@"orelse" => node,
24792486 .@"catch" => node,
......@@ -2967,12 +2974,6 @@ pub const LazySrcLoc = union(enum) {
29672974 /// The source location points to the initializer of a var decl.
29682975 /// The Decl is determined contextually.
29692976 node_offset_var_decl_init: i32,
2970 /// The source location points to a for loop condition expression,
2971 /// found by taking this AST node index offset from the containing
2972 /// Decl AST node, which points to a for loop AST node. Next, navigate
2973 /// to the condition expression.
2974 /// The Decl is determined contextually.
2975 node_offset_for_cond: i32,
29762977 /// The source location points to the first parameter of a builtin
29772978 /// function call, found by taking this AST node index offset from the containing
29782979 /// Decl AST node, which points to a builtin call AST node. Next, navigate
......@@ -3233,7 +3234,6 @@ pub const LazySrcLoc = union(enum) {
32333234 .node_offset_var_decl_section,
32343235 .node_offset_var_decl_addrspace,
32353236 .node_offset_var_decl_init,
3236 .node_offset_for_cond,
32373237 .node_offset_builtin_call_arg0,
32383238 .node_offset_builtin_call_arg1,
32393239 .node_offset_builtin_call_arg2,
test/cases/compile_errors/comptime_if_inside_runtime_for.zig created+14
......@@ -0,0 +1,14 @@
1export fn entry() void {
2 var x: u32 = 0;
3 for(0..1, 1..2) |_, _| {
4 var y = x + if(x == 0) 1 else 0;
5 _ = y;
6 }
7}
8
9// error
10// backend=stage2
11// target=native
12//
13// :4:15: error: value with comptime-only type 'comptime_int' depends on runtime control flow
14// :3:6: note: runtime control flow here