Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(swift): stop a qualified extension naming its qualifier as a parent (#2318)
Nehal kanak kuniyil thottathil56e6fc227c97
diff --git a/packages/core/src/repowise/core/ingestion/queries/swift.scm b/packages/core/src/repowise/core/ingestion/queries/swift.scmindex 26fb6f209..2092227a6 100644--- a/packages/core/src/repowise/core/ingestion/queries/swift.scm+++ b/packages/core/src/repowise/core/ingestion/queries/swift.scm@@ -21,10 +21,17 @@(type_identifier) @symbol.name) @symbol.def-; extension Foo: Protocol — name is nested under user_type+; extension Foo: Protocol: name is nested under user_type.+; The `.` anchor is load-bearing. A qualified `extension Ns.Type: P {}`+; parses as one flat user_type holding two type_identifier children, and an+; unanchored capture matches both, so the qualifier is recorded as a symbol+; and as a conformance parent of its own. Anchor to the last child so only+; the trailing identifier is the name. Single-identifier user_types are+; unaffected.(class_declaration(user_type(type_identifier) @symbol.name+ .)) @symbol.defdiff --git a/tests/unit/ingestion/test_swift_extractors.py b/tests/unit/ingestion/test_swift_extractors.pyindex b047bb9c8..ea720cf04 100644--- a/tests/unit/ingestion/test_swift_extractors.py+++ b/tests/unit/ingestion/test_swift_extractors.py@@ -80,6 +80,41 @@ extension Foo: A, B {}assert ("Foo", "A") in relsassert ("Foo", "B") in rels+ def test_qualified_extension_records_only_the_type(self, parser: ASTParser) -> None:+ # `extension Ns.Type: P {}` parses as ONE flat user_type with two+ # type_identifier children. An unanchored capture matches both, so the+ # qualifier was recorded as conforming to P on its own. Equality is the+ # assertion that matters here: containment would pass against the bug.+ src = b"""\+enum Ns { struct Type {} }+protocol P {}+extension Ns.Type: P {}+"""+ result = parser.parse_file(_file(), src)+ rels = {(r.child_name, r.parent_name) for r in result.heritage}+ assert rels == {("Type", "P")}++ def test_deeply_qualified_extension_takes_the_trailing_identifier(+ self, parser: ASTParser+ ) -> None:+ src = b"""\+enum A { enum B { struct C {} } }+protocol P {}+extension A.B.C: P {}+"""+ result = parser.parse_file(_file(), src)+ rels = {(r.child_name, r.parent_name) for r in result.heritage}+ assert rels == {("C", "P")}++ def test_plain_extension_is_unaffected_by_the_anchor(self, parser: ASTParser) -> None:+ src = b"""\+protocol P {}+extension Foo: P {}+"""+ result = parser.parse_file(_file(), src)+ rels = {(r.child_name, r.parent_name) for r in result.heritage}+ assert rels == {("Foo", "P")}+class TestSwiftExportedImport:def test_exported_import_is_reexport(self, parser: ASTParser) -> None: