Skip to content

Commit fd15d3c

Browse files
committed
fix(native): correct NULL ordering in findCallerByLine and remove self receiver
SQLite ASC ordering puts NULL values first, so (end_line - line) ASC would pick unbounded nodes before any bounded node — inverting the intent. Replace with COALESCE(end_line - line, 999999999) ASC so unbounded nodes sort last. Also remove 'self' from the this/super receiver filter in runPostNativeThisDispatch. In JS/TS files 'self' refers to WindowOrWorkerGlobalScope, not a class instance — including it would produce spurious dispatch edges from Worker call sites.
1 parent f279398 commit fd15d3c

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/domain/graph/builder/stages/native-orchestrator.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -653,12 +653,13 @@ async function runPostNativeThisDispatch(
653653
}
654654

655655
// Find the innermost containing method/function for a call at `line` in `file`.
656-
// NULL end_line sorts last in SQLite ASC → only selected when no bounded node exists.
656+
// COALESCE maps NULL end_line to a large sentinel so unbounded nodes sort last
657+
// (SQLite ASC orders NULLs first, so a raw `end_line - line` would pick them first).
657658
const findCallerByLineStmt = db.prepare(`
658659
SELECT id, name FROM nodes
659660
WHERE file = ? AND kind IN ('method', 'function')
660661
AND line <= ? AND (end_line IS NULL OR end_line >= ?)
661-
ORDER BY (end_line - line) ASC
662+
ORDER BY COALESCE(end_line - line, 999999999) ASC
662663
LIMIT 1
663664
`);
664665

@@ -670,8 +671,10 @@ async function runPostNativeThisDispatch(
670671

671672
for (const [relPath, symbols] of wasmResults) {
672673
for (const call of symbols.calls) {
673-
if (call.receiver !== 'this' && call.receiver !== 'self' && call.receiver !== 'super')
674-
continue;
674+
// Only 'this' and 'super' are class-instance receivers in JS/TS.
675+
// 'self' refers to WindowOrWorkerGlobalScope — not a class instance — so
676+
// filtering it here prevents spurious dispatch edges from Worker call sites.
677+
if (call.receiver !== 'this' && call.receiver !== 'super') continue;
675678

676679
const callerRow = findCallerByLineStmt.get(relPath, call.line, call.line) as
677680
| { id: number; name: string }
@@ -681,7 +684,7 @@ async function runPostNativeThisDispatch(
681684
const targets = resolveThisDispatch(
682685
call.name,
683686
callerRow.name,
684-
call.receiver as 'this' | 'self' | 'super',
687+
call.receiver as 'this' | 'super',
685688
chaCtx,
686689
lookup,
687690
);

0 commit comments

Comments
 (0)