Skip to content

fix(resolver): bare call inside JS class method incorrectly falls back to same-class method lookup #1425

@carlos-alm

Description

@carlos-alm

Problem

In call-resolver.ts, the same-class method lookup (lines 200–213) runs for all bare calls when no exact same-file match is found, regardless of language. This is correct for C#/Java static siblings (e.g., IsValidEmail() inside Validators.ValidateUserValidators.IsValidEmail), but incorrect for JavaScript/TypeScript where bare calls are lexically scoped to the module, not the class.

Repro

Given class-scope.js (from PR #1422):

export class Processor {
  run(x) {
    flush(); // bare call; no module-level 'flush' in scope
  }
  flush() {}
}

The resolver emits Processor.run → Processor.flush (false positive) because:

  1. flush() has no receiver (call.receiver = null)
  2. Exact same-file lookup returns no match (no module-level flush)
  3. Same-class fallback matches Processor.flush — incorrectly

Expected behavior

For JS/TS, bare calls with no same-file/imported match should not fall back to same-class method lookup. The JS scoping rule is: bare foo() is module-scoped, not class-scoped.

Root cause

resolveByMethodOrGlobal in src/domain/graph/builder/call-resolver.ts at lines 195–213 does not gate the same-class fallback on language. It was introduced to support C#/Java static sibling resolution (#1395) but is applied unconditionally.

Fix

Gate the same-class fallback on language identifier (e.g., skip for js/ts/tsx/jsx) or add a caller-language parameter to resolveByMethodOrGlobal.

Also applies to the native Rust engine (crates/codegraph-core/) which mirrors this logic.

Detection

The class-scope.js fixture added in PR #1422 exposes this regression. The 1.0 precision floor on the JS benchmark will fail CI until this is fixed.

Deferred from PR #1422 to keep the fixture PR focused on test infrastructure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions