File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
src/jdk.compiler/share/classes/com/sun/tools/javac/comp
test/langtools/tools/javac/patterns Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -347,8 +347,9 @@ private void handleSwitch(JCTree tree,
347347 }
348348 }
349349 selector = translate (selector );
350- statements .append (make .at (tree .pos ).VarDef (temp , !hasNullCase ? attr .makeNullCheck (selector )
351- : selector ));
350+ boolean needsNullCheck = !hasNullCase && !seltype .isPrimitive ();
351+ statements .append (make .at (tree .pos ).VarDef (temp , needsNullCheck ? attr .makeNullCheck (selector )
352+ : selector ));
352353 VarSymbol index = new VarSymbol (Flags .SYNTHETIC ,
353354 names .fromString (tree .pos + target .syntheticNameChar () + "index" ),
354355 syms .intType ,
Original file line number Diff line number Diff line change 2828
2929/*
3030 * @test
31- * @bug 8262891 8268333 8268896 8269802 8269808 8270151 8269113
31+ * @bug 8262891 8268333 8268896 8269802 8269808 8270151 8269113 8277864
3232 * @summary Check behavior of pattern switches.
3333 * @compile --enable-preview -source ${jdk.version} Switches.java
3434 * @run main/othervm --enable-preview Switches
@@ -85,6 +85,9 @@ void run() {
8585 assertEquals (2 , switchOverNull1 ());
8686 assertEquals (2 , switchOverNull2 ());
8787 assertEquals (2 , switchOverNull3 ());
88+ assertEquals (5 , switchOverPrimitiveInt (0 ));
89+ assertEquals (7 , switchOverPrimitiveInt (1 ));
90+ assertEquals (9 , switchOverPrimitiveInt (2 ));
8891 }
8992
9093 void run (Function <Object , Integer > mapper ) {
@@ -591,6 +594,14 @@ private int switchOverNull3() {
591594 };
592595 }
593596
597+ private int switchOverPrimitiveInt (Integer i ) {
598+ return switch (i ) {
599+ case 0 -> 5 + 0 ;
600+ case Integer j && j == 1 -> 6 + j ;
601+ case Integer j -> 7 + j ;
602+ };
603+ }
604+
594605 //verify that for cases like:
595606 //case ConstantClassClash ->
596607 //ConstantClassClash is interpreted as a field, not as a class
You can’t perform that action at this time.
0 commit comments