Unified: Basic support for extensions - #22558
Merged
Merged
Conversation
Inheritance must be resolvable in the main recursive SCC, prior to unqualified member resolution. We now ensure that the static namespace of the extension target is in the local scope. Note that the instance namespace is not needed here; it is handled in unqualified lookup which is the only case where static name binding needs to worry about instance member lookups.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
A new conformance test uses invalid Swift, and extractor documentation contradicts the new mapping.
Get a fresh assessment by requesting another Copilot review.
Review tier: Balanced
Findings: 1
Open findings (2)
What changed in this PR
Adds structured Swift extension targets and integrates extension members into unified static name binding.
Changes:
- Adds
extension_targetto the unified AST schema and extractor. - Resolves static and instance members across extensions.
- Adds extraction and name-binding coverage.
| File | Description |
|---|---|
unified/extractor/ast_types.yml |
Defines the extension-target field. |
unified/extractor/src/languages/swift/swift.rs |
Maps Swift extended types structurally. |
unified/extractor/tests/corpus/swift/types/extension.output |
Updates generated extractor expectations. |
unified/ql/lib/unified.dbscheme |
Adds extension-target storage. |
unified/ql/lib/codeql/unified/internal/Ast.qll |
Exposes the generated field accessor. |
unified/ql/lib/codeql/unified/internal/StaticNameBinding.qll |
Connects extension and target namespaces. |
unified/ql/test/library-tests/static-name-binding/test.swift |
Updates qualified-target expectations. |
unified/ql/test/library-tests/static-name-binding/extensions.swift |
Adds extension name-binding scenarios. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
An extension can add protocols as base, but not classes. Expanding the test a bit to target a protocol-base and also extension the protocol to add a method with a "default" implementation.
hvitved
reviewed
Sep 15, 2026
hvitved
reviewed
Sep 15, 2026
| baseMethodNoImpl() // $ access=Base.baseMethodNoImpl // with no visible implementation, just resolve to the signature | ||
| baseMethodExt() // $ access=Base.baseMethodExt | ||
| baseMethodExt() // $ access=BaseImpl.baseMethodExt | ||
| baseMethodDefaultImpl() // $ access=Base.baseMethodDefaultImpl access=BaseImpl.baseMethodDefaultImpl |
Contributor
There was a problem hiding this comment.
Should the last access be marked as spurious?
Contributor
Author
There was a problem hiding this comment.
Added a comment to clarify, based on offline discussion
hvitved
approved these changes
Sep 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Adds support for Swift
extensionblocks, aka extension methods.This adds a new field,
ClassLikeNode.getExtensionTarget()for storing the extension target.Two features are not yet handled:
DCA shows an increase in statically-resolvable names by about 2 percentage points.