Fix compilation of infix calls (KT-2929)

#KT-2929 Fixed
This commit is contained in:
Peter Brachwitz
2012-10-29 22:01:22 +01:00
committed by Dmitry Jemerov
parent c4bda6a260
commit 81de3cd46a
4 changed files with 23 additions and 1 deletions
@@ -1831,6 +1831,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
public void invokeMethodWithArguments(CallableMethod callableMethod, JetCallElement expression, StackValue receiver) {
JetExpression calleeExpression = expression.getCalleeExpression();
invokeMethodWithArguments(callableMethod, receiver, calleeExpression);
}
public void invokeMethodWithArguments(CallableMethod callableMethod, StackValue receiver, JetExpression calleeExpression) {
Call call = bindingContext.get(CALL, calleeExpression);
ResolvedCall<? extends CallableDescriptor> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, calleeExpression);
@@ -1839,6 +1843,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
invokeMethodWithArguments(callableMethod, resolvedCall, call, receiver);
}
protected void invokeMethodWithArguments(
@NotNull CallableMethod callableMethod,
@NotNull ResolvedCall<? extends CallableDescriptor> resolvedCall,
@@ -26,6 +26,8 @@ import org.jetbrains.jet.codegen.OwnerKind;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.jet.lang.psi.JetBinaryExpression;
import org.jetbrains.jet.lang.psi.JetCallElement;
import org.jetbrains.jet.lang.psi.JetCallExpression;
import org.jetbrains.jet.lang.psi.JetExpression;
@@ -49,7 +51,11 @@ public class PsiMethodCall implements IntrinsicMethod {
) {
final CallableMethod callableMethod =
state.getTypeMapper().mapToCallableMethod(method, false, OwnerKind.IMPLEMENTATION);
codegen.invokeMethodWithArguments(callableMethod, (JetCallExpression) element, receiver);
if(element instanceof JetBinaryExpression) {
codegen.invokeMethodWithArguments(callableMethod, receiver, ((JetBinaryExpression)element).getOperationReference());
} else {
codegen.invokeMethodWithArguments(callableMethod, (JetCallElement) element, receiver);
}
return StackValue.onStack(callableMethod.getSignature().getAsmMethod().getReturnType());
}
}
@@ -0,0 +1,7 @@
fun foo(): Int {
val a = "test"
val b = "test"
return a compareTo b
}
fun box(): String = if(foo() == 0) "OK" else "Fail"
@@ -191,4 +191,8 @@ public class FunctionGenTest extends CodegenTestCase {
public void testRemoveInIterator() throws Exception {
blackBoxFileWithJava("functions/removeInIterator.kt");
}
public void testKt2929() {
blackBoxFile("regressions/kt2929.kt");
}
}