Closed mpalat closed 2 months ago
Interestingly,
public class X {
public static int foo(int myInt) {
return switch (myInt) {
case int i when i > 10 -> i;
default -> 0;
};
}
public static void main(String argv[]) {
Integer i = 100;
System.out.println(X.foo(i) == i);
}
}
is good. Only in the case of unboxing this issue comes.
Given,
Build error with ST: java.lang.AssertionError: Unexpected operand at stack top at org.eclipse.jdt.internal.compiler.codegen.OperandStack.pop(OperandStack.java:111) at org.eclipse.jdt.internal.compiler.codegen.CodeStream.istore_3(CodeStream.java:5718) at org.eclipse.jdt.internal.compiler.codegen.CodeStream.store(CodeStream.java:7464) at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.generateCode(LocalDeclaration.java:182) at org.eclipse.jdt.internal.compiler.ast.TypePattern.generateCode(TypePattern.java:121) at org.eclipse.jdt.internal.compiler.ast.GuardedPattern.generateCode(GuardedPattern.java:57) at org.eclipse.jdt.internal.compiler.ast.CaseStatement.generateCode(CaseStatement.java:437) at org.eclipse.jdt.internal.compiler.ast.SwitchStatement.statementGenerateCode(SwitchStatement.java:1051) at org.eclipse.jdt.internal.compiler.ast.SwitchExpression.statementGenerateCode(SwitchExpression.java:233) at org.eclipse.jdt.internal.compiler.ast.SwitchStatement.generateCode(SwitchStatement.java:880) at org.eclipse.jdt.internal.compiler.ast.SwitchExpression.generateCode(SwitchExpression.java:318) at org.eclipse.jdt.internal.compiler.ast.ReturnStatement.generateCode(ReturnStatement.java:238) at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:387) at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:323) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:759) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:829) at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.generateCode(CompilationUnitDeclaration.java:416) at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1378) at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:837) at org.eclipse.jdt.core.dom.CompilationUnitResolver.toCompilationUnit(CompilationUnitResolver.java:1467) at org.eclipse.jdt.core.dom.CompilationUnitResolver$ECJCompilationUnitResolver.toCompilationUnit(CompilationUnitResolver.java:117) at org.eclipse.jdt.core.dom.ASTParser.internalCreateASTCached(ASTParser.java:1263) at org.eclipse.jdt.core.dom.ASTParser.lambda$0(ASTParser.java:1142) at org.eclipse.jdt.internal.core.JavaModelManager.cacheZipFiles(JavaModelManager.java:5770) at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1142)
Additional info: A naive commenting of the throw leads to Stack Verification Error as well [well, as expected] Caused by: java.lang.VerifyError: Bad type on operand stack Exception Details: Location: X.foo(Ljava/lang/Integer;)I @37: istore_3 Reason: Type 'java/lang/Integer' (current frame, stack[0]) is not assignable to integer Current Frame: bci: @37 flags: { } locals: { 'java/lang/Integer', 'java/lang/Integer', integer } stack: { 'java/lang/Integer' } Bytecode: 0000000: 2a59 b800 1057 4c03 3d2b 1cba 0016 0000 0000010: aa00 0000 0000 0028 0000 0000 0000 0000 0000020: 0000 0014 2b3e 1d10 0aa4 0006 a700 0804 0000030: 3da7 ffd8 1da7 0004 03ac
Stackmap Table: append_frame(@9,Object[#31],Integer) same_frame(@36) same_frame(@47) append_frame(@52,Integer) chop_frame(@56,1) full_frame(@57,{Object[#31]},{Integer})
ref: issue #2915 as well
CCing @stephan-herrmann also