diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-07-18 17:50:41 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-07-18 19:02:06 -0700 |
| commit | 727b371bbc53b1fcabb6c6899043da3a84195b3c (patch) | |
| tree | 2729cf29bda2ee6e1515b08bcf4cf1b72ee6a067 /src | |
| parent | 0153f3a8f9b93ebef7b5cd70db8560fcac658ce7 (diff) | |
| download | zig-727b371bbc53b1fcabb6c6899043da3a84195b3c.tar.gz zig-727b371bbc53b1fcabb6c6899043da3a84195b3c.zip | |
Sema: fix source location crash for function prototypes
Diffstat (limited to 'src')
| -rw-r--r-- | src/Module.zig | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/Module.zig b/src/Module.zig index 3ae78c30b1..0467688974 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -2146,9 +2146,17 @@ pub const SrcLoc = struct { const tree = try src_loc.file_scope.getTree(gpa); const node = src_loc.declRelativeToNodeIndex(fn_proto_param.fn_proto_node_offset); var buf: [1]Ast.Node.Index = undefined; - const fn_proto_full = tree.fullFnProto(&buf, node).?; - const src_node = fn_proto_full.ast.params[fn_proto_param.param_index]; - return nodeToSpan(tree, src_node); + const full = tree.fullFnProto(&buf, node).?; + var it = full.iterate(tree); + var i: usize = 0; + while (it.next()) |param| : (i += 1) { + if (i == fn_proto_param.param_index) { + if (param.anytype_ellipsis3) |token| return tokenToSpan(tree, token); + if (param.name_token) |token| return tokenToSpan(tree, token); + return nodeToSpan(tree, param.type_expr); + } + } + unreachable; }, .node_offset_bin_lhs => |node_off| { const tree = try src_loc.file_scope.getTree(gpa); @@ -2502,6 +2510,10 @@ pub const SrcLoc = struct { ); } + fn tokenToSpan(tree: *const Ast, token: Ast.TokenIndex) Span { + return tokensToSpan(tree, token, token, token); + } + fn tokensToSpan(tree: *const Ast, start: Ast.TokenIndex, end: Ast.TokenIndex, main: Ast.TokenIndex) Span { const token_starts = tree.tokens.items(.start); var start_tok = start; |
