diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index d42da991ea4..d870b349f9d 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -2083,23 +2083,7 @@ public class ExpressionCodegen extends JetVisitor { getInIntRange(leftValue, rangeExpression, inverted); } else { - StackValue leftValue = gen(expr); - FunctionDescriptor op = - (FunctionDescriptor) bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getOperationReference()); - assert op != null; - Type type = asmType(op.getValueParameters().get(0).getType()); - if (type.getSize() == 1) { - leftValue.put(type, v); - genToJVMStack(expression.getRight()); - v.swap(); - } - else { - leftValue.put(type, v); - genToJVMStack(expression.getRight()); - v.dupX2(); - v.pop(); - } - invokeFunctionNoParams(op, Type.BOOLEAN_TYPE, v); + invokeFunctionByReference(expression.getOperationReference()); if (inverted) { invertBoolean(); } @@ -3332,7 +3316,8 @@ The "returned" value of try expression with no finally is either the last expres while (rangeExpression instanceof JetParenthesizedExpression) { rangeExpression = ((JetParenthesizedExpression) rangeExpression).getExpression(); } - boolean inverted = conditionInRange.getOperationReference().getReferencedNameElementType() == JetTokens.NOT_IN; + JetSimpleNameExpression operationReference = conditionInRange.getOperationReference(); + boolean inverted = operationReference.getReferencedNameElementType() == JetTokens.NOT_IN; if (isIntRangeExpr(rangeExpression)) { getInIntRange(new StackValue.Local(subjectLocal, subjectType), (JetBinaryExpression) rangeExpression, inverted); } @@ -3342,10 +3327,7 @@ The "returned" value of try expression with no finally is either the last expres //genToJVMStack(rangeExpression); //new StackValue.Local(subjectLocal, subjectType).put(TYPE_OBJECT, v); //invokeFunctionNoParams(op, Type.BOOLEAN_TYPE, v); - ResolvedCall resolvedCall = - bindingContext.get(RESOLVED_CALL, conditionInRange.getOperationReference()); - Call call = bindingContext.get(CALL, conditionInRange.getOperationReference()); - invokeFunction(call, StackValue.none(), resolvedCall); + invokeFunctionByReference(operationReference); if (inverted) { invertBoolean(); } @@ -3371,6 +3353,13 @@ The "returned" value of try expression with no finally is either the last expres subjectIsNullable, nextEntry); } + private void invokeFunctionByReference(JetSimpleNameExpression operationReference) { + ResolvedCall resolvedCall = + bindingContext.get(RESOLVED_CALL, operationReference); + Call call = bindingContext.get(CALL, operationReference); + invokeFunction(call, StackValue.none(), resolvedCall); + } + private void invertBoolean() { v.iconst(1); v.xor(Type.INT_TYPE); diff --git a/compiler/testData/codegen/patternMatching/longInRange.jet b/compiler/testData/codegen/patternMatching/longInRange.jet new file mode 100644 index 00000000000..6a6df53f32e --- /dev/null +++ b/compiler/testData/codegen/patternMatching/longInRange.jet @@ -0,0 +1,9 @@ +class LongR { + fun contains(l : Long): Boolean = l == 5.toLong() +} + +fun box(): String { + if (5 !in LongR()) return "fail 1" + if (6 in LongR()) return "fail 2" + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java b/compiler/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java index ebe3b1040d3..009626e3666 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java @@ -80,6 +80,10 @@ public class PatternMatchingTest extends CodegenTestCase { blackBoxFile("patternMatching/range.jet"); } + public void testLongInRange() throws Exception { + blackBoxFile("patternMatching/longInRange.jet"); + } + public void testWhenArgumentIsEvaluatedOnlyOnce() throws Exception { blackBoxFile("patternMatching/whenArgumentIsEvaluatedOnlyOnce.kt"); }