Pick the best-resolving node among name matches. Sets *ambiguous when the * matches can't be reduced to one logical symbol, so resolution never silently * traces (or conflates) the wrong same-named node: * 1. the top score is shared by >1 candidate (a genuine rank/span tie), or * 2. two or more *real* callable definitions share the name — distinct * implementations, not a definition
| 2855 | * unioned by bfs_union_same_name (#546) into one confidently-conflated answer. |
| 2856 | * Body-less .d.ts stubs still union with their implementation (#650). */ |
| 2857 | static int pick_resolved_node(const cbm_node_t *nodes, int count, bool *ambiguous) { |
| 2858 | *ambiguous = false; |
| 2859 | if (count <= 1) { |
| 2860 | return 0; |
| 2861 | } |
| 2862 | int best = 0; |
| 2863 | long best_score = node_resolution_score(&nodes[0]); |
| 2864 | for (int i = 1; i < count; i++) { |
| 2865 | long s = node_resolution_score(&nodes[i]); |
| 2866 | if (s > best_score) { |
| 2867 | best_score = s; |
| 2868 | best = i; |
| 2869 | } |
| 2870 | } |
| 2871 | int top_count = 0; |
| 2872 | int real_def_count = 0; |
| 2873 | for (int i = 0; i < count; i++) { |
| 2874 | if (node_resolution_score(&nodes[i]) == best_score) { |
| 2875 | top_count++; |
| 2876 | } |
| 2877 | if (node_is_real_callable_def(&nodes[i])) { |
| 2878 | real_def_count++; |
| 2879 | } |
| 2880 | } |
| 2881 | if (real_def_count > 1) { |
| 2882 | *ambiguous = true; |
| 2883 | } |
| 2884 | if (top_count > 1) { |
| 2885 | *ambiguous = true; |
| 2886 | } |
| 2887 | return best; |
| 2888 | } |
| 2889 | |
| 2890 | /* BFS from EVERY node sharing the resolved name and merge the results, so the |
| 2891 | * caller/callee set is complete even when one logical symbol is represented by |
no test coverage detected