Use generic invokeFunction() instead of ad-hoc one for in-range conditions in when
This commit is contained in:
@@ -44,15 +44,17 @@ import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
|||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.*;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.*;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||||
|
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibraryNames;
|
import org.jetbrains.jet.lang.types.lang.JetStandardLibraryNames;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static org.jetbrains.jet.codegen.JetTypeMapper.*;
|
import static org.jetbrains.jet.codegen.JetTypeMapper.*;
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContext.CALL;
|
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContext.EXPRESSION_TYPE;
|
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.getNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author max
|
* @author max
|
||||||
@@ -1440,15 +1442,14 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
return generateConstructorCall(expression, (JetSimpleNameExpression) callee, receiver);
|
return generateConstructorCall(expression, (JetSimpleNameExpression) callee, receiver);
|
||||||
}
|
}
|
||||||
else if (funDescriptor instanceof FunctionDescriptor) {
|
else if (funDescriptor instanceof FunctionDescriptor) {
|
||||||
final FunctionDescriptor fd = (FunctionDescriptor) funDescriptor;
|
|
||||||
Call call = bindingContext.get(CALL, expression.getCalleeExpression());
|
Call call = bindingContext.get(CALL, expression.getCalleeExpression());
|
||||||
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||||
VariableAsFunctionResolvedCall variableAsFunctionResolvedCall = (VariableAsFunctionResolvedCall) resolvedCall;
|
VariableAsFunctionResolvedCall variableAsFunctionResolvedCall = (VariableAsFunctionResolvedCall) resolvedCall;
|
||||||
ResolvedCallWithTrace<FunctionDescriptor> functionCall = variableAsFunctionResolvedCall.getFunctionCall();
|
ResolvedCallWithTrace<FunctionDescriptor> functionCall = variableAsFunctionResolvedCall.getFunctionCall();
|
||||||
return invokeFunction(call, functionCall.getResultingDescriptor(), receiver, functionCall);
|
return invokeFunction(call, receiver, functionCall);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return invokeFunction(call, fd, receiver, resolvedCall);
|
return invokeFunction(call, receiver, resolvedCall);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -1458,10 +1459,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
|
|
||||||
private StackValue invokeFunction(
|
private StackValue invokeFunction(
|
||||||
Call call,
|
Call call,
|
||||||
FunctionDescriptor fd,
|
|
||||||
StackValue receiver,
|
StackValue receiver,
|
||||||
ResolvedCall<? extends CallableDescriptor> resolvedCall
|
ResolvedCall<? extends CallableDescriptor> resolvedCall
|
||||||
) {
|
) {
|
||||||
|
FunctionDescriptor fd = (FunctionDescriptor) resolvedCall.getResultingDescriptor();
|
||||||
boolean superCall = false;
|
boolean superCall = false;
|
||||||
ReceiverDescriptor explicitReceiver = call.getExplicitReceiver();
|
ReceiverDescriptor explicitReceiver = call.getExplicitReceiver();
|
||||||
if (explicitReceiver instanceof ExpressionReceiver) {
|
if (explicitReceiver instanceof ExpressionReceiver) {
|
||||||
@@ -2629,7 +2630,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
ResolvedCall<FunctionDescriptor> resolvedCall = bindingContext.get(BindingContext.COMPONENT_RESOLVED_CALL, variableDeclaration);
|
ResolvedCall<FunctionDescriptor> resolvedCall = bindingContext.get(BindingContext.COMPONENT_RESOLVED_CALL, variableDeclaration);
|
||||||
assert resolvedCall != null : "Resolved call is null for " + variableDeclaration.getText();
|
assert resolvedCall != null : "Resolved call is null for " + variableDeclaration.getText();
|
||||||
Call call = CallMaker.makeCall(initializerAsReceiver, (JetExpression) null);
|
Call call = CallMaker.makeCall(initializerAsReceiver, (JetExpression) null);
|
||||||
invokeFunction(call, resolvedCall.getResultingDescriptor(), StackValue.none(), resolvedCall);
|
invokeFunction(call, StackValue.none(), resolvedCall);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -3271,11 +3272,11 @@ The "returned" value of try expression with no finally is either the last expres
|
|||||||
getInIntRange(new StackValue.Local(subjectLocal, subjectType), (JetBinaryExpression) rangeExpression, inverted);
|
getInIntRange(new StackValue.Local(subjectLocal, subjectType), (JetBinaryExpression) rangeExpression, inverted);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
FunctionDescriptor op =
|
ResolvedCall<? extends CallableDescriptor> resolvedCall =
|
||||||
(FunctionDescriptor) bindingContext.get(BindingContext.REFERENCE_TARGET, conditionInRange.getOperationReference());
|
bindingContext.get(BindingContext.RESOLVED_CALL, conditionInRange.getOperationReference());
|
||||||
genToJVMStack(rangeExpression);
|
Call call = bindingContext.get(BindingContext.CALL, conditionInRange.getOperationReference());
|
||||||
new StackValue.Local(subjectLocal, subjectType).put(TYPE_OBJECT, v);
|
|
||||||
invokeFunctionNoParams(op, Type.BOOLEAN_TYPE, v);
|
invokeFunction(call, StackValue.local(subjectLocal, subjectType), resolvedCall);
|
||||||
if (inverted) {
|
if (inverted) {
|
||||||
invertBoolean();
|
invertBoolean();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fun Int.contains(i : Int) = true
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
when (1) {
|
||||||
|
in 2 -> return "OK"
|
||||||
|
else -> return "fail"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -64,6 +64,11 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
factorialTest("controlStructures/break.jet");
|
factorialTest("controlStructures/break.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testInRangeConditionsInWhen() throws Exception {
|
||||||
|
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||||
|
blackBoxFile("controlStructures/inRangeConditionsInWhen.jet");
|
||||||
|
}
|
||||||
|
|
||||||
private void factorialTest(final String name) throws IllegalAccessException, InvocationTargetException {
|
private void factorialTest(final String name) throws IllegalAccessException, InvocationTargetException {
|
||||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||||
loadFile(name);
|
loadFile(name);
|
||||||
|
|||||||
Reference in New Issue
Block a user