Skip to content

fix(resolver): scope this.prop typeMap key to enclosing class to prevent false edges in multi-class files #1323

@carlos-alm

Description

@carlos-alm

Deferred from PR #1314 review (Greptile P1).

Problem

In handlePropWriteTypeMap (src/extractors/javascript.ts), constructor property assignments like this.logger = new Logger(...) are stored in the typeMap as this.logger — without a class-scope qualifier.

When a single file defines two or more classes that both assign the same property name via this.prop = new DifferentCtor(), only the first write survives (setTypeMapEntry discards equal-confidence duplicates). Callers of the second class then resolve this.prop to the wrong type, producing spurious call graph edges.

Impact

  • Before the PR that seeded this: neither edge was resolved (no false positive)
  • After the PR: one class resolves correctly, the other incorrectly — a false positive
  • The JS precision gate is at 1.0, so this will surface as a benchmark failure if a multi-class fixture exercises the pattern

Fix

Key the typeMap entry as ClassName.prop (e.g. Logger.logger) instead of this.prop, where ClassName is the class currently being walked. This requires passing the current class context to handlePropWriteTypeMap.

Example

class A {
  constructor() { this.service = new ServiceA(); }
  doA() { this.service.methodA(); }  // should resolve to ServiceA.methodA
}
class B {
  constructor() { this.service = new ServiceB(); }
  doB() { this.service.methodB(); }  // currently resolves to ServiceA.methodB (wrong!)
}

Deferred from PR #1314 review.

Metadata

Metadata

Assignees

No one assigned

    Labels

    follow-upDeferred work from PR reviews that needs tracking

    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