diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index c6bdb3bc9d7..8b973f8b9ba 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -2138,12 +2138,16 @@ public class ExpressionCodegen extends JetVisitor 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 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 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()); } diff --git a/compiler/testData/codegen/box/defaultArguments/function/augmentedAssignment.kt b/compiler/testData/codegen/box/defaultArguments/function/augmentedAssignment.kt new file mode 100644 index 00000000000..e7ca1f76678 --- /dev/null +++ b/compiler/testData/codegen/box/defaultArguments/function/augmentedAssignment.kt @@ -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 +} diff --git a/compiler/testData/codegen/box/defaultArguments/function/augmentedAssignmentViaBinaryExpression.kt b/compiler/testData/codegen/box/defaultArguments/function/augmentedAssignmentViaBinaryExpression.kt new file mode 100644 index 00000000000..98e53dc3d14 --- /dev/null +++ b/compiler/testData/codegen/box/defaultArguments/function/augmentedAssignmentViaBinaryExpression.kt @@ -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 +} diff --git a/compiler/testData/codegen/box/defaultArguments/function/binaryCall.kt b/compiler/testData/codegen/box/defaultArguments/function/binaryCall.kt new file mode 100644 index 00000000000..f134ad32173 --- /dev/null +++ b/compiler/testData/codegen/box/defaultArguments/function/binaryCall.kt @@ -0,0 +1,3 @@ +fun Int.foo(o: String, k: String = "K") = o + k + +fun box() = 42 foo "O" diff --git a/compiler/testData/codegen/box/defaultArguments/function/binaryExpression.kt b/compiler/testData/codegen/box/defaultArguments/function/binaryExpression.kt new file mode 100644 index 00000000000..b6f36740e89 --- /dev/null +++ b/compiler/testData/codegen/box/defaultArguments/function/binaryExpression.kt @@ -0,0 +1,5 @@ +class A + +fun A.plus(i: A, ok: String = "OK") = ok + +fun box() = A() + A() diff --git a/compiler/testData/codegen/box/defaultArguments/function/contains.kt b/compiler/testData/codegen/box/defaultArguments/function/contains.kt new file mode 100644 index 00000000000..42d089e40fb --- /dev/null +++ b/compiler/testData/codegen/box/defaultArguments/function/contains.kt @@ -0,0 +1,5 @@ +class A + +fun A.contains(i: A, actual: Boolean = true) = actual + +fun box() = if (A() in A()) "OK" else "Fail" diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java index 6358a8676b3..a2d8de9838b 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -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");