diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/OperandStack.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/OperandStack.java index d625a3370f3..b409f4f468e 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/OperandStack.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/OperandStack.java @@ -31,18 +31,21 @@ enum OperandCategory { private Stack stack; private ClassFile classFile; + private Scope scope; public OperandStack() {} public OperandStack(ClassFile classFile) { this.stack = new Stack<>(); this.classFile = classFile; + this.scope = classFile.referenceBinding.scope; } @SuppressWarnings("unchecked") private OperandStack(OperandStack operandStack) { this.stack = (Stack) operandStack.stack.clone(); this.classFile = operandStack.classFile; + this.scope = operandStack.scope; } protected OperandStack copy() { @@ -53,9 +56,6 @@ public void push(TypeBinding typeBinding) { if (typeBinding == null) { throw new AssertionError("Attempt to push null on operand stack!"); //$NON-NLS-1$ } - if (typeBinding instanceof ArrayBinding array && !array.leafComponentType.isReifiable()) { - typeBinding = this.classFile.referenceBinding.scope.createArrayType(erasure(array.leafComponentType), array.dimensions); - } /* 4.9.2 Structural Constraints: ... An instruction operating on values of type int is also permitted to operate on values of type boolean, byte, char, and short. @@ -64,12 +64,17 @@ public void push(TypeBinding typeBinding) { */ this.stack.push(switch(typeBinding.id) { case TypeIds.T_boolean, TypeIds.T_byte, TypeIds.T_short, TypeIds.T_char -> TypeBinding.INT; - default -> typeBinding.erasure(); + default -> erasure(typeBinding); }); } - private TypeBinding erasure(TypeBinding leafComponentType) { - return this.classFile.referenceBinding.scope.getJavaLangObject(); // FIXME: coarse... + private TypeBinding erasure(TypeBinding type) { + if (type instanceof ArrayBinding array) { + TypeBinding leafComponentType = erasure(array.leafComponentType); + return leafComponentType == array.leafComponentType ? type : this.scope.createArrayType(leafComponentType, array.dimensions); //$IDENTITY-COMPARISON$ + } + TypeBinding erasure = type.erasure(); + return erasure.isReifiable() ? erasure : this.scope.getJavaLangObject(); // workaround for IntersectionTypeBinding18.erasure() returning receiver. } public void push(int localSlot) { @@ -81,8 +86,7 @@ public void push(int localSlot) { } public void push(char[] typeName) { - Scope scope = this.classFile.referenceBinding.scope; - Supplier finder = scope.getCommonReferenceBinding(typeName); + Supplier finder = this.scope.getCommonReferenceBinding(typeName); TypeBinding type = finder != null ? finder.get() : TypeBinding.NULL; push(type); }