Skip to content

Cfg: Add consistency check for multiple default cases. - #22510

Open
aschackmull wants to merge 1 commit into
github:mainfrom
aschackmull:cfg/defaultcase-consistency
Open

Cfg: Add consistency check for multiple default cases.#22510
aschackmull wants to merge 1 commit into
github:mainfrom
aschackmull:cfg/defaultcase-consistency

Conversation

@aschackmull

Copy link
Copy Markdown
Contributor

I encountered this in Unified when certain case patterns weren't extracted properly.

(Also, the overview query was missing a few cases, which I drive-by-fixed).

Copilot AI balanced review requested due to automatic review settings September 4, 2026 09:42
@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label Sep 4, 2026
@aschackmull
aschackmull requested a review from a team as a code owner September 4, 2026 09:42

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.

Copilot review overview

🟡 Changes recommended

The new check incorrectly reports valid guarded Python wildcard cases.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Balanced
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity shared/​controlflow/​codeql/​controlflow/​ControlFlowGraph.qll — This flags valid Python match statements as inconsistent. Python maps every wildcard case to…
What changed in this PR

Adds CFG consistency detection for switches with multiple default cases and completes the consistency overview.

Changes:

  • Adds missing consistency overview entries.
  • Fixes a consistency-query name.
  • Detects multiple default cases.
File Description
shared/​controlflow/​codeql/​controlflow/​ControlFlowGraph.qll Extends and corrects CFG consistency checks.

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

* A well-formed switch statement should have at most one default case.
*/
query predicate multipleDefaultCases(Switch s, int defaultCases) {
defaultCases = strictcount(DefaultCase c | s.getCase(_) = c) and

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.

@yoff I think this indicates a mistake in the python CFG - a case _ if cond: should not be a DefaultCase, instead it should be included in predicate matchAll. The reason is that the shared CFG puts a default case last, and multiple default cases can't all be put "last". I.e. in several languages (e.g. in Java) it's valid to have the default case occur before another case, e.g. for the purpose of fallthrough, so it's only the non-default cases that are executed in-order.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants