@@ -1467,30 +1467,25 @@ fn collectVarAccessContainerNodes(
14671467 const symbol_decl = try analyser .lookupSymbolGlobal (handle , handle .tree .source [loc .start .. loc .end ], loc .end ) orelse return ;
14681468 const result = try symbol_decl .resolveType (analyser ) orelse return ;
14691469 const type_expr = try analyser .resolveDerefType (result ) orelse result ;
1470- if (type_expr .isFunc ()) {
1471- const fn_proto_node_handle = type_expr .data .other ; // this assumes that function types can only be Ast nodes
1472- const fn_proto_node = fn_proto_node_handle .node ;
1473- const fn_proto_handle = fn_proto_node_handle .handle ;
1474- if (dot_context .likely == .enum_comparison or dot_context .need_ret_type ) { // => we need f()'s return type
1475- var buf : [1 ]Ast.Node.Index = undefined ;
1476- const full_fn_proto = fn_proto_handle .tree .fullFnProto (& buf , fn_proto_node ).? ;
1477- const has_body = fn_proto_handle .tree .nodes .items (.tag )[fn_proto_node ] == .fn_decl ;
1478- const body = fn_proto_handle .tree .nodes .items (.data )[fn_proto_node ].rhs ;
1479- var node_type = try analyser .resolveReturnType (full_fn_proto , fn_proto_handle , if (has_body ) body else null ) orelse return ;
1480- if (try analyser .resolveUnwrapErrorUnionType (node_type , .payload )) | unwrapped | node_type = unwrapped ;
1481- try node_type .getAllTypesWithHandlesArrayList (arena , types_with_handles );
1482- return ;
1483- }
1484- const fn_param_decl = Analyser.Declaration { .function_parameter = .{
1485- .func = fn_proto_node ,
1486- .param_index = @intCast (dot_context .fn_arg_index ),
1487- } };
1488- const fn_param_decl_with_handle = Analyser.DeclWithHandle { .decl = fn_param_decl , .handle = fn_proto_handle };
1489- const param_type = try fn_param_decl_with_handle .resolveType (analyser ) orelse return ;
1490- try types_with_handles .append (arena , param_type );
1470+ if (! type_expr .isFunc ()) {
1471+ try type_expr .getAllTypesWithHandlesArrayList (arena , types_with_handles );
14911472 return ;
14921473 }
1493- try type_expr .getAllTypesWithHandlesArrayList (arena , types_with_handles );
1474+
1475+ if (dot_context .likely == .enum_comparison or dot_context .need_ret_type ) { // => we need f()'s return type
1476+ var node_type = try analyser .resolveReturnType (type_expr ) orelse return ;
1477+ if (try analyser .resolveUnwrapErrorUnionType (node_type , .payload )) | unwrapped | node_type = unwrapped ;
1478+ try node_type .getAllTypesWithHandlesArrayList (arena , types_with_handles );
1479+ return ;
1480+ }
1481+ const func_node_handle = type_expr .data .other ; // this assumes that function types can only be Ast nodes
1482+ const fn_param_decl : Analyser.Declaration = .{ .function_parameter = .{
1483+ .func = func_node_handle .node ,
1484+ .param_index = @intCast (dot_context .fn_arg_index ),
1485+ } };
1486+ const fn_param_decl_with_handle = Analyser.DeclWithHandle { .decl = fn_param_decl , .handle = func_node_handle .handle };
1487+ const param_type = try fn_param_decl_with_handle .resolveType (analyser ) orelse return ;
1488+ try types_with_handles .append (arena , param_type );
14941489}
14951490
14961491fn collectFieldAccessContainerNodes (
@@ -1528,50 +1523,47 @@ fn collectFieldAccessContainerNodes(
15281523 if (dot_context .likely == .enum_assignment or dot_context .likely == .struct_field ) {
15291524 if (try analyser .resolveOptionalUnwrap (node_type )) | unwrapped | node_type = unwrapped ;
15301525 }
1531- if (node_type .isFunc ()) {
1532- const fn_proto_node_handle = node_type .data .other ; // this assumes that function types can only be Ast nodes
1533- const fn_proto_node = fn_proto_node_handle .node ;
1534- const fn_proto_handle = fn_proto_node_handle .handle ;
1535- var buf : [1 ]Ast.Node.Index = undefined ;
1536- const full_fn_proto = fn_proto_handle .tree .fullFnProto (& buf , fn_proto_node ).? ;
1537- if (dot_context .need_ret_type ) { // => we need f()'s return type
1538- const has_body = fn_proto_handle .tree .nodes .items (.tag )[fn_proto_node ] == .fn_decl ;
1539- const body = fn_proto_handle .tree .nodes .items (.data )[fn_proto_node ].rhs ;
1540- node_type = try analyser .resolveReturnType (full_fn_proto , fn_proto_handle , if (has_body ) body else null ) orelse continue ;
1541- if (try analyser .resolveUnwrapErrorUnionType (node_type , .payload )) | unwrapped | node_type = unwrapped ;
1542- try node_type .getAllTypesWithHandlesArrayList (arena , types_with_handles );
1543- continue ;
1544- }
1545- var maybe_fn_param : ? Ast.full.FnProto.Param = undefined ;
1546- var fn_param_iter = full_fn_proto .iterate (& fn_proto_handle .tree );
1547- // don't have the luxury of referencing an `Ast.full.Call`
1548- // check if the first symbol is a `T` or an instance_of_T
1549- const additional_index : usize = blk : {
1550- // `loc` points to offsets within `handle`, not `node_type.decl.handle`
1551- const field_access_slice = handle .tree .source [loc .start .. loc .end ];
1552- if (field_access_slice [0 ] == '@' ) break :blk 1 ; // assume `@import("..").some.Other{.}`
1553- var symbol_iter = std .mem .tokenizeScalar (u8 , field_access_slice , '.' );
1554- const first_symbol = symbol_iter .next () orelse continue ;
1555- const symbol_decl = try analyser .lookupSymbolGlobal (handle , first_symbol , loc .start ) orelse continue ;
1556- const symbol_type = try symbol_decl .resolveType (analyser ) orelse continue ;
1557- if (! symbol_type .is_type_val ) { // then => instance_of_T
1558- if (try analyser .hasSelfParam (node_type )) break :blk 2 ;
1559- }
1560- break :blk 1 ; // is `T`, no SelfParam
1561- };
1562- for (dot_context .fn_arg_index + additional_index ) | _ | maybe_fn_param = ast .nextFnParam (& fn_param_iter );
1563- const param = maybe_fn_param orelse continue ;
1564- if (param .type_expr == 0 ) continue ;
1565- const param_rcts = try collectContainerNodes (
1566- builder ,
1567- fn_proto_handle ,
1568- offsets .nodeToLoc (fn_proto_handle .tree , param .type_expr ).end ,
1569- dot_context ,
1570- );
1571- for (param_rcts ) | prct | try types_with_handles .append (arena , prct );
1526+ if (! node_type .isFunc ()) {
1527+ try node_type .getAllTypesWithHandlesArrayList (arena , types_with_handles );
15721528 continue ;
15731529 }
1574- try node_type .getAllTypesWithHandlesArrayList (arena , types_with_handles );
1530+
1531+ if (dot_context .need_ret_type ) { // => we need f()'s return type
1532+ node_type = try analyser .resolveReturnType (node_type ) orelse continue ;
1533+ if (try analyser .resolveUnwrapErrorUnionType (node_type , .payload )) | unwrapped | node_type = unwrapped ;
1534+ try node_type .getAllTypesWithHandlesArrayList (arena , types_with_handles );
1535+ continue ;
1536+ }
1537+ // don't have the luxury of referencing an `Ast.full.Call`
1538+ // check if the first symbol is a `T` or an instance_of_T
1539+ const additional_index : usize = blk : {
1540+ // `loc` points to offsets within `handle`, not `node_type.decl.handle`
1541+ const field_access_slice = handle .tree .source [loc .start .. loc .end ];
1542+ if (field_access_slice [0 ] == '@' ) break :blk 0 ; // assume `@import("..").some.Other{.}`
1543+ var symbol_iter = std .mem .tokenizeScalar (u8 , field_access_slice , '.' );
1544+ const first_symbol = symbol_iter .next () orelse continue ;
1545+ const symbol_decl = try analyser .lookupSymbolGlobal (handle , first_symbol , loc .start ) orelse continue ;
1546+ const symbol_type = try symbol_decl .resolveType (analyser ) orelse continue ;
1547+ if (! symbol_type .is_type_val ) { // then => instance_of_T
1548+ if (try analyser .hasSelfParam (node_type )) break :blk 1 ;
1549+ }
1550+ break :blk 0 ; // is `T`, no SelfParam
1551+ };
1552+ const fn_node_handle = node_type .data .other ; // this assumes that function types can only be Ast nodes
1553+ const param_decl : Analyser.Declaration.Param = .{
1554+ .param_index = @truncate (dot_context .fn_arg_index + additional_index ),
1555+ .func = fn_node_handle .node ,
1556+ };
1557+ const param = param_decl .get (fn_node_handle .handle .tree ) orelse continue ;
1558+
1559+ if (param .type_expr == 0 ) continue ;
1560+ const param_rcts = try collectContainerNodes (
1561+ builder ,
1562+ fn_node_handle .handle ,
1563+ offsets .nodeToLoc (fn_node_handle .handle .tree , param .type_expr ).end ,
1564+ dot_context ,
1565+ );
1566+ for (param_rcts ) | prct | try types_with_handles .append (arena , prct );
15751567 }
15761568}
15771569
0 commit comments