fix(symbol-table): index constructors in methodByOwner (#694)

This commit is contained in:
Roshan Warrier 2026-04-08 11:02:02 +05:30 • committed by GitHub
parent be2401061e
commit fe87ff8f74
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View file

@ -216,8 +216,9 @@ export const createSymbolTable = (): SymbolTable => {
}
globalIndex.get(name)!.push(def);
// C2. Methods with ownerId go to methodByOwner index (in addition to globalIndex).
if (type === 'Method' && metadata?.ownerId) {
// C2. Methods and constructors with ownerId go to methodByOwner index
// (in addition to globalIndex).
if ((type === 'Method' || type === 'Constructor') && metadata?.ownerId) {
const key = `${metadata.ownerId}\0${name}`;
const existing = methodByOwner.get(key);
if (existing) {

View file

@ -383,12 +383,18 @@ describe('SymbolTable', () => {
expect(table.lookupMethodByOwner('class:Handler', 'process')).toBeUndefined();
});
it('does NOT index Constructor in methodByOwner', () => {
it('indexes Constructor in methodByOwner', () => {
table.add('src/models.ts', 'User', 'ctor:User', 'Constructor', {
parameterCount: 0,
ownerId: 'class:User',
});
expect(table.lookupMethodByOwner('class:User', 'User')).toBeUndefined();
expect(table.lookupMethodByOwner('class:User', 'User')).toEqual({
nodeId: 'ctor:User',
filePath: 'src/models.ts',
type: 'Constructor',
parameterCount: 0,
ownerId: 'class:User',
});
// But it should be in lookupFuzzyCallable
expect(table.lookupFuzzyCallable('User')).toHaveLength(1);
});