bug(swift): nested constructor in extension resolves to unrelated top-level type
Area
gitnexus (CLI / core / indexing / MCP server)
Summary
An unqualified nested Swift constructor inside an extension is resolved to an unrelated top-level type with the same short name, creating a false CALLS edge.
Context
The standalone example below uses three Swift files and no dependencies. It reproduces with a freshly created index; gitnexus status reports that the index matches all three files and the current commit.
Expected behavior
Within extension Container, Entry(id:text:) resolves to Container.Entry from Types.swift. makeEntry should have no call edge to the top-level Entry in Standalone.swift.
The Swift compiler accepts both the complete example and Types.swift plus Builder.swift alone. The unrelated top-level type has a different memberwise initializer (enabled:).
Actual behavior
context makeEntry reports a call to Struct:Standalone.swift:Entry. Context for that unrelated type reports makeEntry as an incoming caller. Upstream impact reports one direct dependency through the same false edge, with confidence 0.85 and epistemic: "exact".
Steps to reproduce
- Create a new directory containing these three files.
Standalone.swift:
struct Entry {
let enabled: Bool
}Types.swift:
struct Container {
struct Entry {
let id: Int
let text: String
}
}Builder.swift:
extension Container {
static func makeEntry() -> Entry {
Entry(id: 1, text: "sample")
}
}- Initialize a Git repository, commit the example, and check Swift's resolution:
git init
git add Standalone.swift Types.swift Builder.swift
git commit -m "Add Swift scope reproduction"
swiftc -typecheck Standalone.swift Types.swift Builder.swift
swiftc -typecheck Types.swift Builder.swiftBoth type checks pass.
- Build a fresh GitNexus index and query it from that directory:
gitnexus analyze --index-only .
gitnexus status
gitnexus context makeEntry --file Builder.swift --repo "$PWD"
gitnexus context Entry --file Standalone.swift --content --repo "$PWD"
gitnexus impact Entry --file Standalone.swift --direction upstream --depth 1 --repo "$PWD"- Observe the incorrect edge from
Container.makeEntryto the top-levelEntry.
Environment
- GitNexus: 1.6.11
- Node.js: v26.8.2
- OS: macOS 26.6.2, arm64
- Swift compiler: Apple Swift 6.3.3
- Index: freshly generated from the three-file example; status reports current commit and matching file contents
Logs / screenshots
Relevant excerpt from context makeEntry for the standalone example:
{
"epistemic": "exact",
"outgoing": {
"calls": [
{
"uid": "Struct:Standalone.swift:Entry",
"name": "Entry",
"filePath": "Standalone.swift"
}
]
}
}This makes the unrelated top-level type appear to have a caller and makes its impact result incorrect.
Source: abhigyanpatwari/GitNexus