update jdt.core to I20221201-0500
diff --git a/org.eclipse.jdt.core.tests.compiler/pom.xml b/org.eclipse.jdt.core.tests.compiler/pom.xml
index aff8d28..07ffc01 100644
--- a/org.eclipse.jdt.core.tests.compiler/pom.xml
+++ b/org.eclipse.jdt.core.tests.compiler/pom.xml
@@ -15,7 +15,7 @@
<parent>
<artifactId>tests-pom</artifactId>
<groupId>org.eclipse.jdt</groupId>
- <version>4.26.0-SNAPSHOT</version>
+ <version>4.27.0-SNAPSHOT</version>
<relativePath>../tests-pom/</relativePath>
</parent>
<artifactId>org.eclipse.jdt.core.tests.compiler</artifactId>
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java
index 3d53811..754fdf3 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java
@@ -29,7 +29,7 @@
static {
// TESTS_NUMBERS = new int [] { 40 };
// TESTS_RANGE = new int[] { 1, -1 };
-// TESTS_NAMES = new String[] { "testBug578132_001"};
+// TESTS_NAMES = new String[] { "testIssue449_001"};
}
private static String previewLevel = "19";
@@ -5304,4 +5304,21 @@
},
"Pass");
}
+ public void testIssue449_001() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " Object obj = null;\n"+
+ " var a = switch (obj) {\n"+
+ " case null -> 1;\n"+
+ " default -> 2;\n"+
+ " };\n"+
+ " System.out.println(a);\n"+
+ " }\n" +
+ "}"
+ },
+ "1");
+ }
}
diff --git a/org.eclipse.jdt.core.tests.model/pom.xml b/org.eclipse.jdt.core.tests.model/pom.xml
index a0c110f..a0c04d4 100644
--- a/org.eclipse.jdt.core.tests.model/pom.xml
+++ b/org.eclipse.jdt.core.tests.model/pom.xml
@@ -15,7 +15,7 @@
<parent>
<artifactId>tests-pom</artifactId>
<groupId>org.eclipse.jdt</groupId>
- <version>4.26.0-SNAPSHOT</version>
+ <version>4.27.0-SNAPSHOT</version>
<relativePath>../tests-pom/</relativePath>
</parent>
<artifactId>org.eclipse.jdt.core.tests.model</artifactId>
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java
index bece420..294ed27 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java
@@ -517,7 +517,7 @@
final TypeBinding resolvedType1 = this.expression.resolvedType;
boolean valueRequired = false;
- if (this.containsPatterns) {
+ if (this.containsPatterns || isNullAndNeedsPatternVar()) {
generateCodeSwitchPatternPrologue(currentScope, codeStream);
valueRequired = true;
transformConstants();
@@ -682,7 +682,7 @@
}
}
private void generateCodeSwitchPatternEpilogue(CodeStream codeStream) {
- if (this.containsPatterns && this.caseLabelElements.size() > 0) {
+ if ((this.containsPatterns && this.caseLabelElements.size() > 0) || isNullAndNeedsPatternVar()) {
codeStream.removeVariable(this.dispatchPatternCopy);
codeStream.removeVariable(this.restartIndexLocal);
}
@@ -1185,8 +1185,18 @@
}
return remainingTypes.isEmpty();
}
+ private boolean isNullAndNeedsPatternVar() {
+ if (this.containsPatterns)
+ return false; // don't bother - already taken care
+ if (!this.containsNull)
+ return false;
+ TypeBinding eType = this.expression != null ? this.expression.resolvedType : null;
+ if (eType == null)
+ return false;
+ return !(eType.isPrimitiveOrBoxedPrimitiveType() || eType.isEnum());
+ }
private void addSecretPatternSwitchVariables(BlockScope upperScope) {
- if (this.containsPatterns) {
+ if (this.containsPatterns || isNullAndNeedsPatternVar()) {
this.scope = new BlockScope(upperScope);
this.dispatchPatternCopy = new LocalVariableBinding(SecretPatternVariableName, this.expression.resolvedType, ClassFileConstants.AccDefault, false);
this.scope.addLocalVariable(this.dispatchPatternCopy);
diff --git a/org.eclipse.jdt.core/pom.xml b/org.eclipse.jdt.core/pom.xml
index 983ab94..71c7690 100644
--- a/org.eclipse.jdt.core/pom.xml
+++ b/org.eclipse.jdt.core/pom.xml
@@ -14,7 +14,7 @@
<parent>
<artifactId>eclipse.jdt.core</artifactId>
<groupId>org.eclipse.jdt</groupId>
- <version>4.26.0-SNAPSHOT</version>
+ <version>4.27.0-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.32.0-SNAPSHOT</version>