diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java b/src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java index a326712e2ae..dd45781aa6e 100644 --- a/src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java +++ b/src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java @@ -118,12 +118,13 @@ import static org.objectweb.asm.Opcodes.IFEQ; import static org.objectweb.asm.Opcodes.IFNE; import static org.objectweb.asm.Opcodes.IF_ACMPEQ; -import static org.objectweb.asm.Opcodes.IF_ACMPNE; import static org.objectweb.asm.Opcodes.INSTANCEOF; import static org.objectweb.asm.Opcodes.POP; public class BinaryExpressionHelper { // compare + private static final MethodCaller compareIdenticalMethod = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "compareIdentical"); + private static final MethodCaller compareNotIdenticalMethod = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "compareNotIdentical"); private static final MethodCaller compareEqualMethod = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "compareEqual"); private static final MethodCaller compareNotEqualMethod = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "compareNotEqual"); private static final MethodCaller compareToMethod = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "compareTo"); @@ -351,11 +352,11 @@ public void eval(final BinaryExpression expression) { break; case COMPARE_IDENTICAL: - evaluateIdentity(expression, true); + evaluateCompareExpression(compareIdenticalMethod, expression); break; case COMPARE_NOT_IDENTICAL: - evaluateIdentity(expression, false); + evaluateCompareExpression(compareNotIdenticalMethod, expression); break; default: @@ -363,44 +364,6 @@ public void eval(final BinaryExpression expression) { } } - private void evaluateIdentity(BinaryExpression expression, boolean identical) { - AsmClassGenerator acg = controller.getAcg(); - MethodVisitor mv = controller.getMethodVisitor(); - OperandStack operandStack = controller.getOperandStack(); - TypeChooser typeChooser = controller.getTypeChooser(); - - Expression lhs = expression.getLeftExpression(); - ClassNode leftType = typeChooser.resolveType(lhs, controller.getClassNode()); - - Expression rhs = expression.getRightExpression(); - ClassNode rightType = typeChooser.resolveType(rhs, controller.getClassNode()); - - boolean leftPrimitive = ClassHelper.isPrimitiveType(leftType); - boolean rightPrimitive = ClassHelper.isPrimitiveType(rightType); - if (leftPrimitive && rightPrimitive) { - BinaryExpressionMultiTypeDispatcher helper = new BinaryExpressionMultiTypeDispatcher(controller); - boolean done = helper.doPrimitiveCompare(leftType, rightType, expression); - if (done) return; - } - - lhs.visit(acg); - if (leftPrimitive) operandStack.box(); - - rhs.visit(acg); - if (rightPrimitive) operandStack.box(); - - Label trueCase = operandStack.jump(identical ? IF_ACMPEQ : IF_ACMPNE); - ConstantExpression.PRIM_FALSE.visit(acg); - Label end = new Label(); - mv.visitJumpInsn(GOTO, end); - - mv.visitLabel(trueCase); - ConstantExpression.PRIM_TRUE.visit(acg); - - mv.visitLabel(end); - operandStack.replace(ClassHelper.boolean_TYPE, 3); - } - @Deprecated protected void assignToArray(final Expression parent, final Expression receiver, final Expression index, final Expression rhsValueLoader) { assignToArray(parent, receiver, index, rhsValueLoader, false); diff --git a/src/test/groovy/bugs/Groovy11415.groovy b/src/test/groovy/bugs/Groovy11415.groovy deleted file mode 100644 index 47864b3166d..00000000000 --- a/src/test/groovy/bugs/Groovy11415.groovy +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package bugs - -import org.codehaus.groovy.classgen.asm.AbstractBytecodeTestCase - -import static groovy.test.GroovyAssert.isAtLeastJdk - -final class Groovy11415 extends AbstractBytecodeTestCase { - void testIdentity() { - assert compile(method: 'isIdentical', ''' - def isIdentical (Object obj) { - if (obj === 'abc') return true - return false - } - ''').hasSequence([ - 'LDC "abc"', - 'IF_ACMPEQ L1', - 'ICONST_0', - 'GOTO L2' - ]) - } - - void testNotIdentity() { - assert compile(method: 'isNotIdentical', ''' - def isNotIdentical (Object obj) { - if (obj !== 'abc') return true - return false - } - ''').hasSequence([ - 'LDC "abc"', - 'IF_ACMPNE L1', - 'ICONST_0', - 'GOTO L2' - ]) - } -}