authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-18 17:50:41-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-18 19:02:06-07:00
log727b371bbc53b1fcabb6c6899043da3a84195b3c
tree2729cf29bda2ee6e1515b08bcf4cf1b72ee6a067
parent0153f3a8f9b93ebef7b5cd70db8560fcac658ce7

Sema: fix source location crash for function prototypes


1 files changed, 15 insertions(+), 3 deletions(-)

src/Module.zig+15-3
...@@ -2146,9 +2146,17 @@ pub const SrcLoc = struct {...@@ -2146,9 +2146,17 @@ pub const SrcLoc = struct {
2146 const tree = try src_loc.file_scope.getTree(gpa);2146 const tree = try src_loc.file_scope.getTree(gpa);
2147 const node = src_loc.declRelativeToNodeIndex(fn_proto_param.fn_proto_node_offset);2147 const node = src_loc.declRelativeToNodeIndex(fn_proto_param.fn_proto_node_offset);
2148 var buf: [1]Ast.Node.Index = undefined;2148 var buf: [1]Ast.Node.Index = undefined;
2149 const fn_proto_full = tree.fullFnProto(&buf, node).?;2149 const full = tree.fullFnProto(&buf, node).?;
2150 const src_node = fn_proto_full.ast.params[fn_proto_param.param_index];2150 var it = full.iterate(tree);
2151 return nodeToSpan(tree, src_node);2151 var i: usize = 0;
2152 while (it.next()) |param| : (i += 1) {
2153 if (i == fn_proto_param.param_index) {
2154 if (param.anytype_ellipsis3) |token| return tokenToSpan(tree, token);
2155 if (param.name_token) |token| return tokenToSpan(tree, token);
2156 return nodeToSpan(tree, param.type_expr);
2157 }
2158 }
2159 unreachable;
2152 },2160 },
2153 .node_offset_bin_lhs => |node_off| {2161 .node_offset_bin_lhs => |node_off| {
2154 const tree = try src_loc.file_scope.getTree(gpa);2162 const tree = try src_loc.file_scope.getTree(gpa);
...@@ -2502,6 +2510,10 @@ pub const SrcLoc = struct {...@@ -2502,6 +2510,10 @@ pub const SrcLoc = struct {
2502 );2510 );
2503 }2511 }
25042512
2513 fn tokenToSpan(tree: *const Ast, token: Ast.TokenIndex) Span {
2514 return tokensToSpan(tree, token, token, token);
2515 }
2516
2505 fn tokensToSpan(tree: *const Ast, start: Ast.TokenIndex, end: Ast.TokenIndex, main: Ast.TokenIndex) Span {2517 fn tokensToSpan(tree: *const Ast, start: Ast.TokenIndex, end: Ast.TokenIndex, main: Ast.TokenIndex) Span {
2506 const token_starts = tree.tokens.items(.start);2518 const token_starts = tree.tokens.items(.start);
2507 var start_tok = start;2519 var start_tok = start;