Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Thomann2019-02-22 03:14:39 +0000
committerManoj Palat2019-02-22 03:14:39 +0000
commit41e7973f4d4b6a9095b746124a1174ca3bfcbd5a (patch)
treea464175754c541fed3f04bdf9bdbc6a9d8153bb3
parentce88cb13b15fbd28376cd9f9cc3207043563910e (diff)
downloadeclipse.jdt.core-41e7973f4d4b6a9095b746124a1174ca3bfcbd5a.tar.gz
eclipse.jdt.core-41e7973f4d4b6a9095b746124a1174ca3bfcbd5a.tar.xz
eclipse.jdt.core-41e7973f4d4b6a9095b746124a1174ca3bfcbd5a.zip
Bug 544556 - [12] [codegen] Switch expression - Operand Stack Overflow -Y20190222-0110
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java26
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java9
2 files changed, 32 insertions, 3 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java
index 29bc46acfa..512af7f814 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java
@@ -2104,4 +2104,30 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
null,
new String[] {"--enable-preview"});
}
+ public void testBug544556() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public int foo(int i) {\n" +
+ " @SuppressWarnings(\"preview\")\n" +
+ " int v =\n" +
+ " switch(switch(i) {\n" +
+ " case 0 -> { break 2; }\n" +
+ " default -> { break 3; }\n" +
+ " }) {\n" +
+ " case 0 -> { break 0; }\n" +
+ " default -> { break 1; }\n" +
+ " };\n" +
+ " return v == 1 ? v : 0;\n" +
+ " }\n" +
+ " public static void main(String[] argv) {\n" +
+ " System.out.println(new X().foo(0));\n" +
+ " }\n" +
+ "}"
+ },
+ "1",
+ null,
+ new String[] {"--enable-preview"});
+ }
} \ No newline at end of file
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 3ab19de9fa..adb1c90c0d 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
@@ -515,12 +515,15 @@ public class SwitchStatement extends Expression {
codeStream.recordPositionsFrom(codeStream.position, this.sourceEnd, true);
defaultLabel.place();
}
- if (this.expectedType() != null) {
- TypeBinding expectedType = this.expectedType().erasure();
+ if (this instanceof SwitchExpression) {
+ TypeBinding switchResolveType = this.resolvedType;
+ if (this.expectedType() != null) {
+ switchResolveType = this.expectedType().erasure();
+ }
boolean optimizedGoto = codeStream.lastAbruptCompletion == -1;
// if the last bytecode was an optimized goto (value is already on the stack) or an enum switch without default case, then we need to adjust the
// stack depth to reflect the fact that there is an value on the stack (return type of the switch expression)
- codeStream.recordExpressionType(expectedType, optimizedGoto ? 0 : 1, optimizedGoto || isEnumSwitchWithoutDefaultCase);
+ codeStream.recordExpressionType(switchResolveType, optimizedGoto ? 0 : 1, optimizedGoto || isEnumSwitchWithoutDefaultCase);
}
codeStream.recordPositionsFrom(pc, this.sourceStart);
} finally {

Back to the top