diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java index 702875665e8..8a9820ec4f9 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java @@ -55,7 +55,8 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.*; class CodegenAnnotatingVisitor extends JetVisitorVoid { private static final TokenSet BINARY_OPERATIONS = - TokenSet.create(JetTokens.PLUS, JetTokens.MINUS, JetTokens.MUL, JetTokens.DIV, JetTokens.PERC, JetTokens.RANGE); + TokenSet.orSet(JetTokens.AUGMENTED_ASSIGNMENTS, + TokenSet.create(JetTokens.PLUS, JetTokens.MINUS, JetTokens.MUL, JetTokens.DIV, JetTokens.PERC, JetTokens.RANGE)); private final Map anonymousSubclassesCount = new HashMap(); diff --git a/compiler/testData/codegen/boxWithJava/samAdapters/operators/augmentedAssignmentPure.java b/compiler/testData/codegen/boxWithJava/samAdapters/operators/augmentedAssignmentPure.java new file mode 100644 index 00000000000..ca769a8b559 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/samAdapters/operators/augmentedAssignmentPure.java @@ -0,0 +1,21 @@ +class JavaClass { + void plusAssign(Runnable i) { + i.run(); + } + + void minusAssign(Runnable i) { + i.run(); + } + + void timesAssign(Runnable i) { + i.run(); + } + + void divAssign(Runnable i) { + i.run(); + } + + void modAssign(Runnable i) { + i.run(); + } +} diff --git a/compiler/testData/codegen/boxWithJava/samAdapters/operators/augmentedAssignmentPure.kt b/compiler/testData/codegen/boxWithJava/samAdapters/operators/augmentedAssignmentPure.kt new file mode 100644 index 00000000000..cabf08c76bd --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/samAdapters/operators/augmentedAssignmentPure.kt @@ -0,0 +1,25 @@ +fun box(): String { + val obj = JavaClass() + + var v1 = "FAIL" + obj += { v1 = "OK" } + if (v1 != "OK") return "plus: $v1" + + var v2 = "FAIL" + obj -= { v2 = "OK" } + if (v2 != "OK") return "minus: $v2" + + var v3 = "FAIL" + obj *= { v3 = "OK" } + if (v3 != "OK") return "times: $v3" + + var v4 = "FAIL" + obj /= { v4 = "OK" } + if (v4 != "OK") return "div: $v4" + + var v5 = "FAIL" + obj %= { v5 = "OK" } + if (v5 != "OK") return "mod: $v5" + + return "OK" +} diff --git a/compiler/testData/codegen/boxWithJava/samAdapters/operators/augmentedAssignmentViaSimpleBinary.java b/compiler/testData/codegen/boxWithJava/samAdapters/operators/augmentedAssignmentViaSimpleBinary.java new file mode 100644 index 00000000000..07b3b5df1ac --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/samAdapters/operators/augmentedAssignmentViaSimpleBinary.java @@ -0,0 +1,26 @@ +class JavaClass { + JavaClass plus(Runnable i) { + i.run(); + return this; + } + + JavaClass minus(Runnable i) { + i.run(); + return this; + } + + JavaClass times(Runnable i) { + i.run(); + return this; + } + + JavaClass div(Runnable i) { + i.run(); + return this; + } + + JavaClass mod(Runnable i) { + i.run(); + return this; + } +} diff --git a/compiler/testData/codegen/boxWithJava/samAdapters/operators/augmentedAssignmentViaSimpleBinary.kt b/compiler/testData/codegen/boxWithJava/samAdapters/operators/augmentedAssignmentViaSimpleBinary.kt new file mode 100644 index 00000000000..037ae0f0510 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/samAdapters/operators/augmentedAssignmentViaSimpleBinary.kt @@ -0,0 +1,25 @@ +fun box(): String { + var obj = JavaClass() + + var v1 = "FAIL" + obj += { v1 = "OK" } + if (v1 != "OK") return "plus: $v1" + + var v2 = "FAIL" + obj -= { v2 = "OK" } + if (v2 != "OK") return "minus: $v2" + + var v3 = "FAIL" + obj *= { v3 = "OK" } + if (v3 != "OK") return "times: $v3" + + var v4 = "FAIL" + obj /= { v4 = "OK" } + if (v4 != "OK") return "div: $v4" + + var v5 = "FAIL" + obj %= { v5 = "OK" } + if (v5 != "OK") return "mod: $v5" + + return "OK" +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java index d5db3611429..cf250398cfc 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java @@ -232,6 +232,16 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/boxWithJava/samAdapters/operators"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("augmentedAssignmentPure.kt") + public void testAugmentedAssignmentPure() throws Exception { + doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/operators/augmentedAssignmentPure.kt"); + } + + @TestMetadata("augmentedAssignmentViaSimpleBinary.kt") + public void testAugmentedAssignmentViaSimpleBinary() throws Exception { + doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/operators/augmentedAssignmentViaSimpleBinary.kt"); + } + @TestMetadata("binary.kt") public void testBinary() throws Exception { doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/operators/binary.kt");