fix: preserve guarded multi-pattern hierarchy#6809
Open
martinfrancois wants to merge 1 commit into
Open
Conversation
martinfrancois
force-pushed
the
agent/issue-6808-unnamed-pattern-hierarchy
branch
from
July 17, 2026 17:17
a06058c to
6de9d82
Compare
martinfrancois
marked this pull request as ready for review
July 17, 2026 18:41
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.
Summary
Preserve both patterns and the separate boolean guard in a switch label such as
case First _, Second _ when enabled.Fixes #6808.
Problem
First _andSecond _are two alternative patterns: the first matches aFirstvalue and the second matches aSecondvalue.enabledis a separate boolean guard. Spoon must build oneCtCasePatternfor each alternative and attachenabledas theCtCaseguard.ECJ stores the two patterns inside one
EitherOrMultiPattern, then wraps that node and the guard condition in aGuardedPattern. For this label, the correct alternative count is two. Spoon uses that count while it receives ECJ's child nodes: the first two pattern children belong to the comma-separated label, and the following expression is the guard.Spoon counted alternatives only when
EitherOrMultiPatternwas the direct case expression. The wrapper therefore made Spoon expect one pattern instead of two. Spoon attachedFirst _correctly, then treated theCtTypePatternforSecond _as the guard. Model construction failed because aCtTypePatternbelongs under aCtCasePattern, not directly under aCtCaseguard.Change
GuardedPatternonly while counting its alternatives.CtCasePatternfor each alternative.CtTypePatternbelow itsCtCasePattern.CtCase.Tests
mvn -q -Dtest=spoon.test.pattern.SwitchPatternTest#testMultipleTypePatternsWithGuardInSwitch testpasses.mvn -q -DskipTests installandmvn -q spotless:checkpass.Full test suite
The complete Java 25 suite passes 4,461 tests with 0 failures, 0 errors, and 16 skipped.