Fix default argument method calls

In some cases, calls of methods with default arguments were invoked via the
actual generated method, not via the "...$default" accessor
This commit is contained in:
Alexander Udalov
2013-09-03 19:57:15 +04:00
parent 329d724c1e
commit 723d5ef564
7 changed files with 74 additions and 7 deletions
@@ -2138,12 +2138,16 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
}
}
int mask = pushMethodArguments(resolvedCall, callableMethod.getValueParameterTypes());
pushArgumentsAndInvoke(resolvedCall, callableMethod);
}
private void pushArgumentsAndInvoke(@NotNull ResolvedCall<?> resolvedCall, @NotNull CallableMethod callable) {
int mask = pushMethodArguments(resolvedCall, callable.getValueParameterTypes());
if (mask == 0) {
callableMethod.invokeWithNotNullAssertion(v, state, resolvedCall);
callable.invokeWithNotNullAssertion(v, state, resolvedCall);
}
else {
callableMethod.invokeDefaultWithNotNullAssertion(v, state, resolvedCall, mask);
callable.invokeDefaultWithNotNullAssertion(v, state, resolvedCall, mask);
}
}
@@ -2947,8 +2951,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
receiver.put(receiver.type, v);
}
pushMethodArguments(resolvedCall, callable.getValueParameterTypes());
callable.invokeWithNotNullAssertion(v, state, resolvedCall);
pushArgumentsAndInvoke(resolvedCall, callable);
if (keepReturnValue) {
value.store(callable.getReturnType(), v);
}
@@ -3038,8 +3042,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
bindingContext.get(BindingContext.RESOLVED_CALL, expression.getOperationReference());
assert resolvedCall != null;
genThisAndReceiverFromResolvedCall(StackValue.none(), resolvedCall, callable);
pushMethodArguments(resolvedCall, callable.getValueParameterTypes());
callable.invokeWithNotNullAssertion(v, state, resolvedCall);
pushArgumentsAndInvoke(resolvedCall, callable);
return returnValueAsStackValue(op, callable.getSignature().getAsmMethod().getReturnType());
}
@@ -0,0 +1,12 @@
var result = "Fail"
class A
fun A.plusAssign(a: A, s: String = "OK") {
result = s
}
fun box(): String {
A() += A()
return result
}
@@ -0,0 +1,14 @@
var result = "Fail"
class A
fun A.plus(a: A, s: String = "OK"): A {
result = s
return this
}
fun box(): String {
var a = A()
a += A()
return result
}
@@ -0,0 +1,3 @@
fun Int.foo(o: String, k: String = "K") = o + k
fun box() = 42 foo "O"
@@ -0,0 +1,5 @@
class A
fun A.plus(i: A, ok: String = "OK") = ok
fun box() = A() + A()
@@ -0,0 +1,5 @@
class A
fun A.contains(i: A, actual: Boolean = true) = actual
fun box() = if (A() in A()) "OK" else "Fail"
@@ -1607,6 +1607,31 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/box/defaultArguments/function"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("augmentedAssignment.kt")
public void testAugmentedAssignment() throws Exception {
doTest("compiler/testData/codegen/box/defaultArguments/function/augmentedAssignment.kt");
}
@TestMetadata("augmentedAssignmentViaBinaryExpression.kt")
public void testAugmentedAssignmentViaBinaryExpression() throws Exception {
doTest("compiler/testData/codegen/box/defaultArguments/function/augmentedAssignmentViaBinaryExpression.kt");
}
@TestMetadata("binaryCall.kt")
public void testBinaryCall() throws Exception {
doTest("compiler/testData/codegen/box/defaultArguments/function/binaryCall.kt");
}
@TestMetadata("binaryExpression.kt")
public void testBinaryExpression() throws Exception {
doTest("compiler/testData/codegen/box/defaultArguments/function/binaryExpression.kt");
}
@TestMetadata("contains.kt")
public void testContains() throws Exception {
doTest("compiler/testData/codegen/box/defaultArguments/function/contains.kt");
}
@TestMetadata("extentionFunction.kt")
public void testExtentionFunction() throws Exception {
doTest("compiler/testData/codegen/box/defaultArguments/function/extentionFunction.kt");