Skip to content

Unified: Allow pattern-less parameters. - #22791

Open
aschackmull wants to merge 3 commits into
github:mainfrom
aschackmull:unified/cfg-enumcase-param
Open

aschackmull wants to merge 3 commits into
github:mainfrom
aschackmull:unified/cfg-enumcase-param

Conversation

@aschackmull

Copy link
Copy Markdown
Contributor

Parameters of Swift enum case constructors currently don't have a pattern extracted, so the CFG breaks. In these cases the CFG library expects the parameter itself to act as pattern. This fixes a bunch of consistency errors.

@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label Oct 9, 2026
@aschackmull
aschackmull force-pushed the unified/cfg-enumcase-param branch from 0d23722 to 5b98c6c Compare October 9, 2026 09:13
@aschackmull
aschackmull marked this pull request as ready for review October 9, 2026 09:22
@aschackmull
aschackmull requested a review from a team as a code owner October 9, 2026 09:22
Copilot AI balanced review requested due to automatic review settings October 9, 2026 09:22

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

The fallback makes parameter type syntax participate in control flow through generic child traversal.

1 open finding
What changed in this PR

Allows patternless Swift enum-case parameters to participate in the CFG, resolving dead-end consistency failures.

Changes:

  • Falls back to the parameter itself when no pattern exists.
  • Updates generated consistency expectations.
File Description
unified/​ql/​lib/​codeql/​unified/​internal/​ControlFlowGraph.qll Adds pattern fallback behavior.
unified/​ql/​test/​library-tests/​BasicTest/​CONSISTENCY/​CfgConsistency.expected Removes resolved dead ends.
unified/​ql/​test/​library-tests/​dataflow/​CONSISTENCY/​CfgConsistency.expected Removes resolved dead ends.
unified/​ql/​test/​library-tests/​local-name-binding/​CONSISTENCY/​CfgConsistency.expected Removes resolved dead ends.
unified/​ql/​test/​library-tests/​static-name-binding/​CONSISTENCY/​CfgConsistency.expected Removes resolved dead end.
unified/​ql/​test/​library-tests/​type-inference/​CONSISTENCY/​CfgConsistency.expected Removes resolved dead ends.
unified/​ql/​test/​query-tests/​security/​CWE-022/​PathInjection/​CONSISTENCY/​CfgConsistency.expected Removes resolved dead end.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +59 to +63
AstNode getPattern() {
result = super.getPattern()
or
not exists(super.getPattern()) and result = this
}
asgerf
asgerf previously approved these changes Oct 9, 2026

@asgerf asgerf 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.

LGTM. The comment from CCR might be worth looking at, but feel free to merge otherwise

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.

It looks like these empty files were not deleted?

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.

(Here is what I normally run: find unified/ql/test -name "*Consistency.expected" -size 0 -print -delete)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Huh, I mostly just used --learn, so I guess that's not sufficient.

@aschackmull

Copy link
Copy Markdown
Contributor Author

The comment from CCR might be worth looking at, but feel free to merge otherwise

Yeah, I think that comment is actually accurate and something I'll want to address.

@aschackmull

Copy link
Copy Markdown
Contributor Author

The comment from CCR might be worth looking at, but feel free to merge otherwise

Yeah, I think that comment is actually accurate and something I'll want to address.

There are a couple of different ways to address this, but given that parameters are fully known to the shared lib, then I think it makes the most sense for the shared lib to own this concern. So I think this is best suited for a followup PR.

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.

4 participants