Skip to content

Commit

Permalink
Improved fix
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-sankaran committed Jan 31, 2025
1 parent a164233 commit 2c94136
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@ enum OperandCategory {

private Stack<TypeBinding> 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<TypeBinding>) operandStack.stack.clone();
this.classFile = operandStack.classFile;
this.scope = operandStack.scope;
}

protected OperandStack copy() {
Expand All @@ -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.
Expand All @@ -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) {
Expand All @@ -81,8 +86,7 @@ public void push(int localSlot) {
}

public void push(char[] typeName) {
Scope scope = this.classFile.referenceBinding.scope;
Supplier<ReferenceBinding> finder = scope.getCommonReferenceBinding(typeName);
Supplier<ReferenceBinding> finder = this.scope.getCommonReferenceBinding(typeName);
TypeBinding type = finder != null ? finder.get() : TypeBinding.NULL;
push(type);
}
Expand Down

0 comments on commit 2c94136

Please sign in to comment.