On Mon, 16 Nov 2026 15:56:41 GMT, Aggelos Biboudis <[email protected]> wrote:
> Removes the preview implementation of Primitive Types in Patterns, > `instanceof`, and `switch` from JDK 28. The withdrawn feature is rejected > even with `--enable-preview`. > > The compiler changes restore the pre-preview rules while preserving > subsequent fixes (listed on the CSR). JShell, diagnostics, and affected > regression tests are updated accordingly. > > I would like to explicitely mention the two components described on the CSR > (for symmetry): > > 1. `SwitchBootstraps.typeSwitch` no longer performs exact numeric conversions > or accepts `Long`, `Float`, `Double`, or `Boolean` constant labels. It also > rejects `void.class` labels. Primitive selector descriptors and primitive > class labels remain accepted through boxing and matching via their wrapper > classs, preserving compatibility with non-preview record-pattern binaries > generated by JDK 23-27. I documented this in the JavaDoc of `typeSwitch` as > well. This behavior is tested anew in > `SwitchBootstrapsTest::testPrimitiveTypeCompatibility` and > `NoPrimitivesAsCaseLabelsFor21::findPrimitiveBootstrapArguments`. > > 1. `ExactConversionsSupport` and all its public methods are retained; > references to the withdrawn preview specification are removed. > > Since this removal is not merely a `git revert`. The removal preserves the > fixes. The restored rules are adapted to the current compiler. No > functionality should be lost. > > Among the tests there is a new one `PrimitivePatternsRemoved` covering all > eight primitive types, extended `instanceof` forms. It runs with preview > disabled and enabled, and with `--release 21` and `22`. > > --------- > - [x] I confirm that I make this contribution in accordance with the [OpenJDK > Interim AI Policy](https://openjdk.org/legal/ai). src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ExhaustivenessComputer.java line 715: > 713: Type pattype = types.erasure(bp.type); > 714: > 715: return seltype.isPrimitive() || pattype.isPrimitive() adding parens around the || could also help src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ExhaustivenessComputer.java line 973: > 971: Type existingPatternType = types.erasure(existingPattern.type()); > 972: Type currentPatternType = types.erasure(currentPattern.type()); > 973: if (existingPatternType.isPrimitive() ^ > currentPatternType.isPrimitive()) { another xor src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ExhaustivenessComputer.java line 976: > 974: return false; > 975: } > 976: if (existingPatternType.isPrimitive()) { These lines are repeated in few places -- is there a place for a common helper maybe? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/33919#discussion_r4630725662 PR Review Comment: https://git.openjdk.org/jdk/pull/33919#discussion_r4630732943 PR Review Comment: https://git.openjdk.org/jdk/pull/33919#discussion_r4630741170
