From 8784ff4fab97b3aa21a0c2a4b5dba39fc6886baa Mon Sep 17 00:00:00 2001 From: Srikanth Sankaran <131454720+srikanth-sankaran@users.noreply.github.com> Date: Fri, 12 Apr 2024 12:08:48 +0530 Subject: [PATCH] [Switch Expression] Internal compiler error: java.util.EmptyStackException (#2329) * Fixes https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2322 --- .../internal/compiler/codegen/CodeStream.java | 2 +- .../SwitchExpressionsYieldTest.java | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java index 7066cd2179d..fec4fa3e717 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java @@ -3980,7 +3980,7 @@ public void i2c() { public void i2d() { this.countLabels = 0; this.stackDepth++; - pushTypeBinding(1, TypeBinding.INT); + pushTypeBinding(1, TypeBinding.DOUBLE); if (this.stackDepth > this.stackMax) this.stackMax = this.stackDepth; if (this.classFileOffset >= this.bCodeStream.length) { diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java index 417978e6f0d..de8b76d7ca7 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java @@ -7130,4 +7130,35 @@ public static void notmain(String [] args) { }, ""); } + // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2322 + // [Switch Expression] Internal compiler error: java.util.EmptyStackException at java.base/java.util.Stack.peek + public void testIssue2322() { + if (this.complianceLevel < ClassFileConstants.JDK14) + return; + this.runConformTest( + new String[] { + "X.java", + """ + public class X { + public static void main(String [] args) { + int lineCount = 10; + long time = 1000; + print((int) (lineCount * 10000.0 / time)); + print((double) (lineCount * 10000.0 / time)); + System.out.println(switch(lineCount) { + default -> { + try { + yield "OK"; + } finally { + + } + } + }); + } + static void print(double d) {} + } + """ + }, + "OK"); + } }