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 {...@@ -2459,7 +2459,7 @@ pub const SrcLoc = struct {
2459 return nodeToSpan(tree, node_datas[asm_output].lhs);2459 return nodeToSpan(tree, node_datas[asm_output].lhs);
2460 },2460 },
24612461
2462 .node_offset_for_cond, .node_offset_if_cond => |node_off| {2462 .node_offset_if_cond => |node_off| {
2463 const tree = try src_loc.file_scope.getTree(gpa);2463 const tree = try src_loc.file_scope.getTree(gpa);
2464 const node = src_loc.declRelativeToNodeIndex(node_off);2464 const node = src_loc.declRelativeToNodeIndex(node_off);
2465 const node_tags = tree.nodes.items(.tag);2465 const node_tags = tree.nodes.items(.tag);
...@@ -2471,9 +2471,16 @@ pub const SrcLoc = struct {...@@ -2471,9 +2471,16 @@ pub const SrcLoc = struct {
2471 .while_simple,2471 .while_simple,
2472 .while_cont,2472 .while_cont,
2473 .@"while",2473 .@"while",
2474 => tree.fullWhile(node).?.ast.cond_expr,
2475
2474 .for_simple,2476 .for_simple,
2475 .@"for",2477 .@"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
2478 .@"orelse" => node,2485 .@"orelse" => node,
2479 .@"catch" => node,2486 .@"catch" => node,
...@@ -2967,12 +2974,6 @@ pub const LazySrcLoc = union(enum) {...@@ -2967,12 +2974,6 @@ pub const LazySrcLoc = union(enum) {
2967 /// The source location points to the initializer of a var decl.2974 /// The source location points to the initializer of a var decl.
2968 /// The Decl is determined contextually.2975 /// The Decl is determined contextually.
2969 node_offset_var_decl_init: i32,2976 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,
2976 /// The source location points to the first parameter of a builtin2977 /// The source location points to the first parameter of a builtin
2977 /// function call, found by taking this AST node index offset from the containing2978 /// function call, found by taking this AST node index offset from the containing
2978 /// Decl AST node, which points to a builtin call AST node. Next, navigate2979 /// Decl AST node, which points to a builtin call AST node. Next, navigate
...@@ -3233,7 +3234,6 @@ pub const LazySrcLoc = union(enum) {...@@ -3233,7 +3234,6 @@ pub const LazySrcLoc = union(enum) {
3233 .node_offset_var_decl_section,3234 .node_offset_var_decl_section,
3234 .node_offset_var_decl_addrspace,3235 .node_offset_var_decl_addrspace,
3235 .node_offset_var_decl_init,3236 .node_offset_var_decl_init,
3236 .node_offset_for_cond,
3237 .node_offset_builtin_call_arg0,3237 .node_offset_builtin_call_arg0,
3238 .node_offset_builtin_call_arg1,3238 .node_offset_builtin_call_arg1,
3239 .node_offset_builtin_call_arg2,3239 .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