mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-12-05 00:27:26 +00:00
* fix(swift,dart): type chained receivers through hoisted return types (#3498) Swift and Dart hoist every method's return-type binding out of the class body onto the Module scope, as C# does, but neither set hoistTypeBindingsToModule. The receiver walk therefore never looked there, and svc.getUser().save() had no receiver type. Both now set it. The flag alone was not safe. The hoisted bindings are keyed by bare method name, so with class A { getUser() -> User } and class B { getUser() -> Admin } in one file the Module scope keeps only B's entry, and a.getUser().save() resolved to Admin.save. C# and TypeScript already do this on main. So there is a new ScopeResolver toggle, hoistedTypeBindingsRequireOwner, which Swift and Dart also set. With it, the walk accepts a hoisted binding only when its declaration anchor encloses the declaration of a member of that name owned by the receiver's class. Otherwise it keeps climbing, and declines if nothing passes. The four walk-ups in compound-receiver.ts now share one helper. The toggle is opt-in. With the guard on everywhere, TypeScript loses correct edges where two same-named methods happen to return the same type (11 rows in inferred-field-receiver-matrix), because the Module map cannot hold both. Swift and Dart never had those edges. Bench: swift plainChain, plainDeepChain, optionalChain and nonNullAssert (INVISIBLE-GAP) and dart plainChain, plainDeepChain and optionalChain (VISIBLE-GAP) now RESOLVE with correct targets. No other cell and no count-arm figure moves. The inferred-field matrix gains correct Inner.compute edges for Swift (3 rows) and Dart (7 Alien rows). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(scope): guard hoisted return ownership * fix(scope): gate hoisted return replay checks * fix(scope): preserve parameterized return replay Keep exact callee return facts when ancestor candidates have matching known parameter types, while refusing same-owner overload ties. Refs #3666 * fix(scope): preserve known variadic return replay Compare complete captured parameter vectors across distinct ancestor owners, including variadic methods with unknown numeric arity. Keep unknown Swift parameter slots instead of compressing them away. Refs #3666 * test(swift): retain reviewed receiver fixtures * fix(scope): retain unknown overload candidates Keep unknown parameter slots possible without hiding conversion overloads. Check return-owner precision without requiring valid calls to stay unresolved. Refs #3498 * fix(scope): preserve conversion suppression Keep explicit empty conversion results final when parameter metadata is unknown. Add exact positive controls for receiver-fixture liveness. Refs #3498 --------- Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
3.7 KiB
TypeScript
89 lines
3.7 KiB
TypeScript
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { getRelationships, runPipelineFromRepo, writeFixtureRepo } from './resolvers/helpers.js';
|
|
import { isLanguageAvailable } from '../../src/core/tree-sitter/parser-loader.js';
|
|
import { SupportedLanguages } from '../../src/config/supported-languages.js';
|
|
|
|
describe.skipIf(!isLanguageAvailable(SupportedLanguages.Swift))(
|
|
'Swift assigned override returns',
|
|
() => {
|
|
it.each([
|
|
{ label: 'fixed parameters', parameter: '_ ids: Int', args: '1' },
|
|
{ label: 'variadic parameters', parameter: '_ ids: Int...', args: '1, 2' },
|
|
])('retains the exact bound return for $label', async ({ parameter, args }) => {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'gn-swift-override-replay-'));
|
|
try {
|
|
writeFixtureRepo(root, {
|
|
'Main.swift': `class User { func save() {} }
|
|
class Admin: User { override func save() {} }
|
|
class Base { func find(${parameter}) -> User { User() } }
|
|
class Child: Base { override func find(${parameter}) -> Admin { Admin() } }
|
|
func probeBound(svc: Child) { let u = svc.find(${args}); u.save() }
|
|
`,
|
|
});
|
|
const result = await runPipelineFromRepo(root, () => {}, {});
|
|
const calls = getRelationships(result, 'CALLS').filter(
|
|
(edge) => edge.source === 'probeBound' && edge.target === 'save',
|
|
);
|
|
expect(calls).toHaveLength(1);
|
|
expect(calls[0]?.rel.targetId).toBe('Function:Main.swift:Admin.save#0');
|
|
} finally {
|
|
fs.rmSync(root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
it.each([
|
|
{
|
|
label: 'different fixed parameter types',
|
|
base: '_ value: Int',
|
|
child: '_ value: String',
|
|
args: '1',
|
|
},
|
|
{
|
|
label: 'different variadic parameter types',
|
|
base: '_ values: Int...',
|
|
child: '_ values: String...',
|
|
args: '1, 2',
|
|
},
|
|
{
|
|
label: 'different metatype parameter types',
|
|
base: '_ kind: User.Type, _ values: Int...',
|
|
child: '_ kind: Admin.Type, _ values: Int...',
|
|
args: 'User.self, 1, 2',
|
|
},
|
|
])('preserves return-owner precision for $label', async ({ base, child, args }) => {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'gn-swift-overload-replay-'));
|
|
try {
|
|
writeFixtureRepo(root, {
|
|
'Main.swift': `class User { func save() {} }
|
|
class Admin { func save() {} }
|
|
class Base { func find(${base}) -> User { User() } }
|
|
class Child: Base { func find(${child}) -> Admin { Admin() } }
|
|
func probeBound(svc: Child) { let u = svc.find(${args}); u.save() }
|
|
func probeControl(user: User) { user.save() }
|
|
`,
|
|
});
|
|
const result = await runPipelineFromRepo(root, () => {}, {});
|
|
const calls = getRelationships(result, 'CALLS').filter(
|
|
(edge) => edge.source === 'probeBound' && edge.target === 'save',
|
|
);
|
|
// Call argument types are not captured yet. Check owner precision
|
|
// without requiring the correct inherited result to stay unresolved.
|
|
for (const call of calls) {
|
|
expect(call.rel.targetId).toBe('Function:Main.swift:User.save#0');
|
|
}
|
|
// This supported call checks fixture-local resolution, not completeness
|
|
// of the primary call or coverage of every selective primary-path loss.
|
|
const controlCalls = getRelationships(result, 'CALLS')
|
|
.filter((edge) => edge.source === 'probeControl' && edge.target === 'save')
|
|
.map((edge) => edge.rel.targetId)
|
|
.sort();
|
|
expect(controlCalls).toEqual(['Function:Main.swift:User.save#0']);
|
|
} finally {
|
|
fs.rmSync(root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
},
|
|
);
|