Using invokeFunction() instead of invokeFunctionWithNoParams() when generating in-expressions
This commit is contained in:
@@ -2083,23 +2083,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
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<? extends CallableDescriptor> 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<? extends CallableDescriptor> 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);
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user