Repository navigation
fix(resolution): don't guess project methods for untyped JS built-in method calls - #1941
Closed
danusha2345 wants to merge 1 commit into
Closed
danusha2345 wants to merge 1 commit into
danusha2345 wants to merge 1 commit into
Conversation
…thods The name-only method fallback bound an untyped `lines.map()`, `seen.has(k)` or `p.then()` to whichever project class declared the only `map`/`has`/`then` (confidence 0.7), or to a same-named method via receiver/qualified-name word overlap (0.65). On codegraph's own index that fabricated ~1,200 call edges, most of them into GraphAdapter::map and LRUCache::has/set. For TS/JS-family refs whose method name is a common Array/Map/Set/String/ Promise/RegExp/Object prototype method, the fallback now requires the receiver's words to name a candidate's class (`treeCache.get` -> LRUCache keeps its edge) and otherwise declines. Typed receivers, `this.field` calls and `Class.method` matches resolve before this fallback and are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Sep 27, 2026
Contributor
Author
|
Closing in favour of #2028. It is the same receiver-evidence guard, applied earlier and more strictly. One small note: this PR also listed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a JS/TS member call's receiver has no inferred type,
matchMethodCall's strategy 3 guesses the target from the method name alone. It binds to the only project method with that name (0.7), or to one whose class shares a word with the receiver (0.65).For built-in prototype methods, the guess is almost always wrong:
lines.map(...),seen.has(k),acc.push(x),re.exec(s),params.set(...). Whichever project class happens to declare the onlymaporhasgets every such call as a caller. A parameter declared as an array isn't protected either:The effect on this repo's own index:
GraphAdapter::maphas 684 callers, allArray#map.LRUCache::hasandLRUCache::sethave 362 and 140, mostlySet/Map/URLSearchParams. TheNode::toStringcallers areBuffer#toString.callersandimpactfor these methods are mostly noise.Fix
A curated list,
JS_BUILTIN_METHOD_NAMESinjs-builtins.ts, holds the common methods of Array, Map/Set, String, Promise, RegExp and Object. In strategy 3 only, a JS/TS-family call to one of these names now needs receiver evidence: the receiver's camel-case words must name a candidate's class. For example,treeCache.getcan still reachLRUCache::get. Without that evidence, the call stays unresolved.These paths are unchanged:
private cache: LRUCache,new LRUCache()locals, typed parameters);this.fieldcalls;Class.methodmatches.This is the JS counterpart of the existing
PYTHON_BUILT_IN_METHODSguard.Measured
Each corpus was indexed with
main(ba3c21e) and with this branch. Node counts are identical, no edges were gained, and all lost edges arecalls:GraphAdapter::map684,LRUCache::has362,LRUCache::set140,Node::toString26MemoryFiles::has38,Clients::delete9History::push201,AppCursor::set60,AppBucketFill::fill8I read about 40 random lost edges, plus every
toString/execone, and all were wrong. I also matched every variable declared as a target class (: Xor= new X) against the lost receivers and found 0 hits, so no true edge was lost. Examples of removed edges:acc.push→History::push,embeddedLinkCache.seton a module-levelnew Map()→AppCursor::set, andcontext.fill()on a canvas context →AppBucketFill::fill.Not fixed here: word-overlap evidence still lets a few wrong edges through, such as
srcCache.geton a realMap→LRUCache::getat 0.65. Tightening that would also drop true*Cacheedges.Tests
The new
__tests__/js-builtin-method-calls.test.tshas 8 cases:main: the repro,Set#has, andPromise#thenagainst project methods with those names.newlocal, a typed parameter, name evidence (treeCache.get), and a lone method with a non-builtin name.The full suite passes.
🤖 Generated with Claude Code