Skip to content

Commit 5f00b7d

Browse files
committed
fix(resolver): add confidence filter to typeName branch in resolveByMethodOrGlobal (#1427)
The typeName lookup (typeMap-resolved receiver) was the only remaining byName call in resolveByMethodOrGlobal without a computeConfidence >= 0.5 guard. Apply the same filter to close the gap and add two unit tests covering the same-dir (pass) and distant (filtered) cases.
1 parent 0a4950e commit 5f00b7d

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/domain/graph/builder/call-resolver.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ export function resolveByMethodOrGlobal(
106106
}
107107

108108
if (typeName) {
109-
const typed = lookup.byName(`${typeName}.${call.name}`).filter((n) => n.kind === 'method');
109+
const typed = lookup
110+
.byName(`${typeName}.${call.name}`)
111+
.filter((n) => n.kind === 'method' && computeConfidence(relPath, n.file, null) >= 0.5);
110112
if (typed.length > 0) return typed;
111113

112114
// Prototype alias: `Foo.prototype.bar = identifier` seeds typeMap['Foo.bar'] = { type: identifier }.

tests/unit/call-resolver.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,31 @@ describe('resolveByMethodOrGlobal — static receiver confidence filter (#1398)'
118118
expect(result).toEqual([]);
119119
});
120120
});
121+
122+
describe('resolveByMethodOrGlobal — typeName branch confidence filter (#1398)', () => {
123+
it('returns same-directory typed method target (confidence 0.7 >= 0.5)', () => {
124+
const target = { id: 3, file: 'app/Foo.cs', kind: 'method' };
125+
const lookup = makeLookup({ 'Foo.bar': [target] });
126+
// typeMap entry: 'f' -> 'Foo' (e.g. from `let f = new Foo()`)
127+
const result = resolveByMethodOrGlobal(
128+
lookup,
129+
{ name: 'bar', receiver: 'f' },
130+
'app/Main.cs',
131+
new Map([['f', 'Foo']]),
132+
);
133+
expect(result).toEqual([target]);
134+
});
135+
136+
it('filters out distant typed method target (confidence 0.3 < 0.5)', () => {
137+
const target = { id: 4, file: 'lib/util/Foo.cs', kind: 'method' };
138+
const lookup = makeLookup({ 'Foo.bar': [target] });
139+
// typeMap entry: 'f' -> 'Foo' — but the definition lives in a distant subtree
140+
const result = resolveByMethodOrGlobal(
141+
lookup,
142+
{ name: 'bar', receiver: 'f' },
143+
'app/main/Main.cs',
144+
new Map([['f', 'Foo']]),
145+
);
146+
expect(result).toEqual([]);
147+
});
148+
});

0 commit comments

Comments
 (0)