mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-09-11 22:53:04 +00:00
* feat(cpp): add standard-conversion-sequence ranking to overload resolution (#1578) Introduce `ConversionRankFn` abstraction and `cppConversionRank` implementation to disambiguate C++ overloaded calls by argument-to-parameter conversion cost. Exact type match (rank 0) beats standard arithmetic conversion (rank 2), which beats non-viable mismatch (Infinity). Thread the rank function through `narrowOverloadCandidates`, `pickImplicitThisOverload`, `pickOverload`, and `pickUniqueGlobalCallable` via the `ScopeResolver.conversionRankFn` contract. Add `findAllCallableBindingsInScope` scope walker for collecting all overloads at the first binding scope. Guard against false ambiguity suppression when candidates span different files (local-shadows-import preservation). * fix: address Claude review findings on conversion-rank PR Finding 1 (HIGH): add tests that exercise the conversion ranker. - p('a') with p(int)/p(double): char→int promotion (rank 1) beats char→double conversion (rank 2), forcing step 4b in narrowOverloadCandidates. Exact-type filter misses both overloads. - h(42, 2.5) with h(int,int)/h(double,double): multi-arg tied total score forces the ranker, both candidates score 2 → suppressed. Finding 2 (HIGH): unify multi-candidate suppression across all paths. - Non-ADL free-call: suppress when narrowed.length > 1 (same-file guard), mirroring ADL merged-candidate behavior. - ADL ordinary-only: same pattern. - pickOverload: return OVERLOAD_AMBIGUOUS when candidates.length > 1 after normalized-ambiguity check. - Case 0.5 (this receiver): set ambiguous=true when narrowed > 1. Finding 3+4 (MEDIUM): implement rank-1 integral promotions. - char→int and bool→int now return rank 1 (ISO C++ [conv.prom]). - Updated comment to remove misleading ISO table header; document only the post-normalization ranking that is actually implemented. - Updated ConversionRankFn JSDoc in overload-narrowing.ts. 218/218 C++ tests pass (registry-primary). Legacy: 186+32. * fix: implement pairwise dominance comparison for overload ranking Replace the summed per-slot conversion cost with ISO C++-aligned pairwise dominance comparison ([over.ics.rank]). F1 is better than F2 only when F1 is not worse for every argument and strictly better for at least one. Non-dominated candidates are returned; if multiple remain they are genuinely ambiguous. This fixes false CALLS edges for asymmetric multi-arg overloads: h('a', 2.5) against h(int,int) / h(double,double) — the old summed cost picked h(double,double) (cost 2 < 3), but ISO C++ considers the call ambiguous because h(int,int) is better at arg 0 via char promotion. The pairwise check correctly finds neither dominates. Add h('a', 2.5) test case asserting zero CALLS edges alongside the existing h(42, 2.5) symmetric-tie test. 218/218 C++ tests pass (registry-primary). Legacy: 186+32. * docs: update step 4b JSDoc to reflect pairwise dominance --------- Co-authored-by: Gergő Magyar <gergomagyar@icloud.com>
33 lines
1.2 KiB
C++
33 lines
1.2 KiB
C++
#pragma once
|
|
|
|
class Service {
|
|
public:
|
|
// Variant 1 & 3: f(int) vs f(double)
|
|
void f(int x);
|
|
void f(double x);
|
|
|
|
// Variant 2: g(int) vs g(long) — both normalize to 'int'
|
|
void g(int x);
|
|
void g(long x);
|
|
|
|
// Variant 4: multi-arg tied total score
|
|
void h(int a, int b);
|
|
void h(double a, double b);
|
|
|
|
// Variant 5: char-literal promotion (exercises conversion ranker)
|
|
void p(int x);
|
|
void p(double x);
|
|
|
|
// Inline: call sites live inside the class scope so the scope-chain
|
|
// walk finds the Class scope, enabling pickImplicitThisOverload to
|
|
// resolve overloads against the declaration-side Method nodes (which
|
|
// carry distinct parameterTypes and graph-node IDs).
|
|
void run() {
|
|
f(2.5); // Variant 1: double literal -> f(double) wins (exact > standard)
|
|
f(42); // Variant 3: int literal -> f(int) wins (exact > standard)
|
|
g(42); // Variant 2: int/long both normalize to 'int' -> ambiguous
|
|
h(42, 2.5); // Variant 4: incomparable — neither dominates the other -> ambiguous
|
|
h('a', 2.5);// Variant 6: asymmetric — h(int,int) better at arg0 (promotion), h(double,double) better at arg1 (exact) -> ambiguous
|
|
p('a'); // Variant 5: char literal -> p(int) wins via promotion (rank 1 < rank 2)
|
|
}
|
|
};
|