zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 9e925a7acce05a69a26fe186acffb47dca326a11 (tree)
parent 5a313192e668501f7ab04b2f1d55b92a3cf33a0e
Author: schtvn <schteven.codes@gmail.com>
Date:   Mon, 17 Feb 2025 22:30:49 -0800

Clean up duplicate code in decl_fields_fallible

Diffstat:
Mlib/docs/wasm/main.zig | 15+++++----------
1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/lib/docs/wasm/main.zig b/lib/docs/wasm/main.zig @@ -387,18 +387,13 @@ fn decl_fields_fallible(decl_index: Decl.Index) ![]Ast.Node.Index { .type_function => { const node_tags = ast.nodes.items(.tag); - // Find the return statement + // If the type function returns a reference to another type function, get the fields from there + if (decl.get_type_fn_return_type_fn()) |function_decl| { + return decl_fields_fallible(function_decl); + } + // If the type function returns a container, such as a `struct`, read that container's fields if (decl.get_type_fn_return_expr()) |return_expr| { switch (node_tags[return_expr]) { - .call, .call_comma, .call_one, .call_one_comma => { - const node_data = ast.nodes.items(.data); - const function = node_data[return_expr].lhs; - const token = ast.nodes.items(.main_token)[function]; - const name = ast.tokenSlice(token); - if (decl.lookup(name)) |function_decl| { - return decl_fields_fallible(function_decl); - } - }, .container_decl, .container_decl_trailing, .container_decl_two, .container_decl_two_trailing, .container_decl_arg, .container_decl_arg_trailing => { return ast_decl_fields_fallible(ast, return_expr); },