#3262·GitNexus

bug(swift): nested constructor in extension resolves to unrelated top-level type

Author: dpearson2699Created Sep 11, 2026Updated Sep 11, 2026

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

  1. Create a new directory containing these three files.

Standalone.swift:

swift
struct Entry {
    let enabled: Bool
}

Types.swift:

swift
struct Container {
    struct Entry {
        let id: Int
        let text: String
    }
}

Builder.swift:

swift
extension Container {
    static func makeEntry() -> Entry {
        Entry(id: 1, text: "sample")
    }
}
  1. Initialize a Git repository, commit the example, and check Swift's resolution:
bash
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.swift

Both type checks pass.

  1. Build a fresh GitNexus index and query it from that directory:
bash
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"
  1. Observe the incorrect edge from Container.makeEntry to the top-level Entry.

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:

json
{
  "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