Skip to content

Unified: Expand basic optional chaining support - #23298

Draft
asgerf wants to merge 5 commits into
github:mainfrom
asgerf:asgerf-optional-chaining
Draft

asgerf wants to merge 5 commits into
github:mainfrom
asgerf:asgerf-optional-chaining

Conversation

@asgerf

@asgerf asgerf commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 3372fa9dee11b3b3d0175637551e907cab4c21ad

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ Extractor unit, corpus, and Swift pipeline tests pass.
↑ Unified dataflow, type-inference, and CommandInjection tests pass.
↓ Hosted checks are still running: clippy, qldoc, analyze, two sync checks, framework coverage artifacts, and analyze (rust).
Diagnosis confidence 9.5/10 ↑ Regressions confirmed both missing optional write-back traversal and non-optional weak-capture inference.
↑ Added targeted setter-flow and weak-capture call-resolution/data-flow coverage.
Evidence fit 10/10 ↑ Each change directly addresses the three reported PR comments, and the corresponding regression tests pass.

Optional chaining x?.y was previously "supported" by the fact that the ? was dropped during extraction, and that data flow bypasses Optional<T> contents. But type inference could still get confused, meaning things like process?.arguments was not recognized as a sink.

This PR extracts the ? as a post-fix unary operator, unwraps the optional type in type inference. At the end of the access chain it should wrap the type in Optional<T> again, but this is not yet implemented, and I think it matters slightly less in practice. It would make sense to wait for the AccessChain class from here to get merged before implementing that.

@asgerf asgerf changed the title Swift: Add basic optional chaining support Unified: Expand basic optional chaining support Dec 2, 2026
@asgerf
asgerf force-pushed the asgerf-optional-chaining branch from f30c4ab to 052a0f0 Compare December 2, 2026 13:04
asgerf and others added 4 commits December 3, 2026 09:57
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@asgerf
asgerf force-pushed the asgerf-optional-chaining branch from 052a0f0 to 5221795 Compare December 3, 2026 09:00
@asgerf asgerf added the no-change-note-required This PR does not need a change note label Dec 3, 2026
@asgerf
asgerf marked this pull request as ready for review December 3, 2026 09:53
@asgerf
asgerf requested review from a team as code owners December 3, 2026 09:53
Copilot AI adaptive review requested due to automatic review settings December 3, 2026 09:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved issues break weak-capture call resolution and optional value-type setter dataflow, while the command-injection baseline still records an expectation failure.

3 open issues
What changed in this PR

Expands Swift optional-chaining support in Unified so type inference and security models can recognize members accessed through optional values. Wrapping the final chain result in Optional remains deferred.

Changes:

  • Extracts ? as a postfix operator and unwraps optional types during inference.
  • Preserves data flow through optional chaining.
  • Adds regression cases and refreshes extractor and query expectations.
File Description
unified/​ql/​test/​query-tests/​security/​CWE-312/​CleartextLogging/​CleartextLogging.expected Updates paths through optional accesses.
unified/​ql/​test/​query-tests/​security/​CWE-078/​CommandInjection/​CommandInjection.expected Records a newly detected optional-property sink.
unified/​ql/​test/​library-tests/​type-inference/​type-inference.expected Adds optional-chaining inference results.
unified/​ql/​test/​library-tests/​type-inference/​optional-chaining.swift Tests optional members, chains, and calls.
unified/​ql/​test/​library-tests/​mad/​test.swift Tests optional source and sink properties.
unified/​ql/​test/​library-tests/​mad/​test.expected Records modeled property results.
unified/​ql/​test/​library-tests/​mad-builtins/​test.swift Tests optional properties without stubs.
unified/​ql/​test/​library-tests/​mad-builtins/​test.expected Records model-only property results.
unified/​ql/​test/​library-tests/​dataflow/​test.expected Adds optional-chaining flow paths.
unified/​ql/​test/​library-tests/​dataflow/​optional-chaining.swift Tests field, method, and subscript flows.
unified/​ql/​test/​library-tests/​controlflow/​basicblock-slices.expected Includes postfix ? nodes.
unified/​ql/​lib/​codeql/​unified/​internal/​typeinference/​TypeInferencePluginSwift.qll Unwraps optional operand types.
unified/​ql/​lib/​codeql/​unified/​internal/​dataflow/​DataFlowPluginSwift.qll Propagates flow through postfix ?.
unified/​extractor/​tests/​corpus/​swift/​optionals-and-errors/​optional-chaining.output Updates nested-chain extraction expectations.
unified/​extractor/​tests/​corpus/​swift/​control-flow/​nested-enum-case-pattern.output Updates optional-call extraction expectations.
unified/​extractor/​tests/​corpus/​swift/​closures/​closure-with-capture-list.output Updates optional access in closures.
unified/​extractor/​src/​languages/​swift/​swift.rs Emits postfix ? while preserving optional patterns.

Review effort: Balanced (adaptive)

@asgerf
asgerf marked this pull request as draft December 3, 2026 10:06
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Unified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants