From 175d37fdc857f0fe471c0401fdc95c996ce06e0a Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Tue, 27 Dec 2016 15:33:01 +0300 Subject: [PATCH] JS: add test to prove that KT-13523 is no more reproducible --- .../augmentedAssignmentWithArrayLHS.kt | 33 +++++++++++++++++++ .../augmentedAssignmentWithArrayLHS.txt | 21 ++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 6 ++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 ++++ ...LightAnalysisModeCodegenTestGenerated.java | 6 ++++ .../semantics/JsCodegenBoxTestGenerated.java | 6 ++++ 6 files changed, 78 insertions(+) create mode 100644 compiler/testData/codegen/box/operatorConventions/augmentedAssignmentWithArrayLHS.kt create mode 100644 compiler/testData/codegen/light-analysis/operatorConventions/augmentedAssignmentWithArrayLHS.txt diff --git a/compiler/testData/codegen/box/operatorConventions/augmentedAssignmentWithArrayLHS.kt b/compiler/testData/codegen/box/operatorConventions/augmentedAssignmentWithArrayLHS.kt new file mode 100644 index 00000000000..0c80cc8edb7 --- /dev/null +++ b/compiler/testData/codegen/box/operatorConventions/augmentedAssignmentWithArrayLHS.kt @@ -0,0 +1,33 @@ +var log = "" + +fun foo(): Int { + log += "foo;" + return 1 +} +fun bar(): Int { + log += "bar;" + return 42 +} + +data class A(val x: Int) { + operator fun plus(other: A) = A(x + other.x) +} + +fun box(): String { + val array = arrayOf(0, 1) + array[foo()] += bar() + + if (array[0] != 0) return "fail1a: ${array[0]}" + if (array[1] != 43) return "fail1b: ${array[0]}" + + log += "!;" + + val objArray = arrayOf(A(0), A(1)) + objArray[foo()] += A(bar()) + if (objArray[0] != A(0)) return "fail2a: ${array[0]}" + if (objArray[1] != A(43)) return "fail2b: ${array[0]}" + + if (log != "foo;bar;!;foo;bar;") return "fail3: $log" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/light-analysis/operatorConventions/augmentedAssignmentWithArrayLHS.txt b/compiler/testData/codegen/light-analysis/operatorConventions/augmentedAssignmentWithArrayLHS.txt new file mode 100644 index 00000000000..c8e554e7366 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/operatorConventions/augmentedAssignmentWithArrayLHS.txt @@ -0,0 +1,21 @@ +public final class A { + private final field x: int + public method (p0: int): void + public final method component1(): int + public synthetic static method copy$default(p0: A, p1: int, p2: int, p3: java.lang.Object): A + public final @org.jetbrains.annotations.NotNull method copy(p0: int): A + public method equals(p0: java.lang.Object): boolean + public final method getX(): int + public method hashCode(): int + public final @org.jetbrains.annotations.NotNull method plus(@org.jetbrains.annotations.NotNull p0: A): A + public method toString(): java.lang.String +} + +public final class AugmentedAssignmentWithArrayLHSKt { + private static @org.jetbrains.annotations.NotNull field log: java.lang.String + public final static method bar(): int + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static method foo(): int + public final static @org.jetbrains.annotations.NotNull method getLog(): java.lang.String + public final static method setLog(@org.jetbrains.annotations.NotNull p0: java.lang.String): void +} diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index fdf967a488a..15323be37a7 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -10595,6 +10595,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("augmentedAssignmentWithArrayLHS.kt") + public void testAugmentedAssignmentWithArrayLHS() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/augmentedAssignmentWithArrayLHS.kt"); + doTest(fileName); + } + @TestMetadata("incDecOnObject.kt") public void testIncDecOnObject() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/incDecOnObject.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 8f6084a0af5..a172bcabae6 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -10595,6 +10595,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("augmentedAssignmentWithArrayLHS.kt") + public void testAugmentedAssignmentWithArrayLHS() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/augmentedAssignmentWithArrayLHS.kt"); + doTest(fileName); + } + @TestMetadata("incDecOnObject.kt") public void testIncDecOnObject() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/incDecOnObject.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java index c7b7e86f6b5..6288c3333fd 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java @@ -10595,6 +10595,12 @@ public class LightAnalysisModeCodegenTestGenerated extends AbstractLightAnalysis doTest(fileName); } + @TestMetadata("augmentedAssignmentWithArrayLHS.kt") + public void testAugmentedAssignmentWithArrayLHS() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/augmentedAssignmentWithArrayLHS.kt"); + doTest(fileName); + } + @TestMetadata("incDecOnObject.kt") public void testIncDecOnObject() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/incDecOnObject.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 77021e01aad..6ca008fc951 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -12456,6 +12456,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } + @TestMetadata("augmentedAssignmentWithArrayLHS.kt") + public void testAugmentedAssignmentWithArrayLHS() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/augmentedAssignmentWithArrayLHS.kt"); + doTest(fileName); + } + @TestMetadata("incDecOnObject.kt") public void testIncDecOnObject() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/incDecOnObject.kt");