Skip to content

Fix getIncludesDefault() for single default case#6667

Open
utafrali wants to merge 1 commit intoINRIA:masterfrom
utafrali:fix/issue-6666-bug-ctcase-getincludesdefault-only-works
Open

Fix getIncludesDefault() for single default case#6667
utafrali wants to merge 1 commit intoINRIA:masterfrom
utafrali:fix/issue-6666-bug-ctcase-getincludesdefault-only-works

Conversation

@utafrali
Copy link
Copy Markdown

@utafrali utafrali commented Mar 8, 2026

Fixes #6666

The condition was only checking the second position for FakeDefaultLiteral when there were two expressions, so single-expression cases were being skipped. Updated it to check both positions and added a test to verify.

@SirYwell
Copy link
Copy Markdown
Collaborator

SirYwell commented Mar 9, 2026

case default isn't valid Java code, it's either default (represented by an empty getCaseExpressions() list) or case null, default (represented by getIncludesDefault() returning true). The reason for the getIncludesDefault() method is that we cannot include the default as a case expression, but need to remember it in a different way. That's only necessary for case null, default, therefore it does not cover default. In other words, case null, default includes default in its case expressions, while default does not have any case expressions, and therefore does not include default.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CtCase<?>::getIncludesDefault only works with multiple case expressions

2 participants