-
Notifications
You must be signed in to change notification settings - Fork 15
fix(resolver): require invocation evidence for object-literal value-ref liveness #2034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: fix/issue-1893-es6-getter-setter-property-reads-are-never
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ import { | |
| } from '../resolver/points-to.js'; | ||
| import { | ||
| type CallNodeLookup, | ||
| collectInvokedPropertyNames, | ||
| findCaller, | ||
| isModuleScopedLanguage, | ||
| resolveCallTargets, | ||
|
|
@@ -1055,6 +1056,10 @@ function buildCallEdges( | |
| // JS path uses (buildPointsToMapForFile, shared via resolver/points-to.js). | ||
| const ptsMap = buildPointsToMapForFile(symbols, importedNames); | ||
| const fnRefBindingLhs = new Set(symbols.fnRefBindings?.map((b) => b.lhs) ?? []); | ||
| // #1895: scoped to this file's own calls only — see collectInvokedPropertyNames | ||
| // doc comment (call-resolver.ts) for why incremental rebuilds use a narrower, | ||
| // same-file view rather than a full-codebase one. | ||
| const invokedPropertyNames = collectInvokedPropertyNames([symbols.calls]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is documented as the same scoping trade-off accepted elsewhere, and a full rebuild will correct it. Worth confirming the team is comfortable with incremental builds potentially surfacing "dead" findings that disappear on the next full run, since that could affect CI dead-code checks that run on incremental watches. |
||
| let edgesAdded = 0; | ||
|
|
||
| for (const call of symbols.calls) { | ||
|
|
@@ -1089,6 +1094,12 @@ function buildCallEdges( | |
| targets = targets.filter( | ||
| (t) => t.kind === 'function' || t.kind === 'method' || t.kind === 'class', | ||
| ); | ||
| // #1895: object-literal-property value-refs additionally require | ||
| // independent evidence the property is actually invoked somewhere — | ||
| // mirrors the same check in resolveFallbackTargets (stages/build-edges.ts). | ||
| if (call.keyExpr && !invokedPropertyNames.has(call.keyExpr)) { | ||
| targets = []; | ||
| } | ||
| } | ||
|
|
||
| edgesAdded += emitIncrementalCallEdges( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
collectInvokedPropertyNamesadds a property name whenever ANY call in the processed files has a non-emptyreceiverand thatname. There is no check that the receiver is plausibly the same dispatch-table object. A completely unrelatedlogger.resolve()orpromise.resolve()call anywhere in the codebase will addresolveto the set and prevent{ resolve: neverCalled }from being flagged dead, even if the actual dispatch table is never read. This is the conservative direction of error (false negative for dead-code), so it won't misclassify live code as dead, but it can cause real dead-code entries to escape detection. Given the existing comment explicitly scopes this as "one hop further" heuristic evidence rather than precise analysis, this is understood — just worth noting for future precision work.