diff options
| author | Veikka Tuominen <git@vexu.eu> | 2023-11-21 13:23:24 +0200 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2023-11-21 13:59:14 +0200 |
| commit | a947f97331595df4ee340bbcfcef7241555c687b (patch) | |
| tree | 2001af089d40b9a42e8ffbd564c85831232dcaf3 /src/Module.zig | |
| parent | f64f3423e4a4d63838a54dfb01f5cd9ea8f68b19 (diff) | |
| download | zig-a947f97331595df4ee340bbcfcef7241555c687b.tar.gz zig-a947f97331595df4ee340bbcfcef7241555c687b.zip | |
Sema: fix bad error location on field init with field access
Closes #14753
Diffstat (limited to 'src/Module.zig')
| -rw-r--r-- | src/Module.zig | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/Module.zig b/src/Module.zig index 828ceb734a..3b554553f7 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -1467,6 +1467,14 @@ pub const SrcLoc = struct { const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len)); return Span{ .start = start, .end = end, .main = start }; }, + .node_offset_field_name_init => |node_off| { + const tree = try src_loc.file_scope.getTree(gpa); + const node = src_loc.declRelativeToNodeIndex(node_off); + const tok_index = tree.firstToken(node) - 2; + const start = tree.tokens.items(.start)[tok_index]; + const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len)); + return Span{ .start = start, .end = end, .main = start }; + }, .node_offset_deref_ptr => |node_off| { const tree = try src_loc.file_scope.getTree(gpa); const node = src_loc.declRelativeToNodeIndex(node_off); @@ -2132,10 +2140,14 @@ pub const LazySrcLoc = union(enum) { /// The payload is offset from the containing Decl AST node. /// The source location points to the field name of: /// * a field access expression (`a.b`), or - /// * the callee of a method call (`a.b()`), or - /// * the operand ("b" node) of a field initialization expression (`.a = b`), or + /// * the callee of a method call (`a.b()`) /// The Decl is determined contextually. node_offset_field_name: i32, + /// The payload is offset from the containing Decl AST node. + /// The source location points to the field name of the operand ("b" node) + /// of a field initialization expression (`.a = b`) + /// The Decl is determined contextually. + node_offset_field_name_init: i32, /// The source location points to the pointer of a pointer deref expression, /// found by taking this AST node index offset from the containing /// Decl AST node, which points to a pointer deref AST node. Next, navigate @@ -2374,6 +2386,7 @@ pub const LazySrcLoc = union(enum) { .node_offset_slice_sentinel, .node_offset_call_func, .node_offset_field_name, + .node_offset_field_name_init, .node_offset_deref_ptr, .node_offset_asm_source, .node_offset_asm_ret_ty, |
