From 5e0f54a30b3e344db7bd6368609b5ad81e75d7c3 Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Fri, 6 Nov 2020 18:58:28 +0500 Subject: [PATCH] [IR] Fixed https://youtrack.jetbrains.com/issue/KT-43159 --- .../ir/FirBlackBoxCodegenTestGenerated.java | 10 ++++++++++ .../lower/loops/handlers/IndicesHandlers.kt | 5 ++--- .../forInIndices/kt43159_ArrayUpperBound.kt | 16 ++++++++++++++++ .../forInIndices/kt43159_GenericArray.kt | 19 +++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 10 ++++++++++ .../LightAnalysisModeTestGenerated.java | 10 ++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 10 ++++++++++ .../IrJsCodegenBoxES6TestGenerated.java | 10 ++++++++++ .../IrJsCodegenBoxTestGenerated.java | 10 ++++++++++ .../semantics/JsCodegenBoxTestGenerated.java | 10 ++++++++++ 10 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/codegen/box/ranges/forInIndices/kt43159_ArrayUpperBound.kt create mode 100644 compiler/testData/codegen/box/ranges/forInIndices/kt43159_GenericArray.kt diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index e258c9ca18b..b818870e693 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -22572,6 +22572,16 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT public void testKt13241_Collection() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInIndices/kt13241_Collection.kt"); } + + @TestMetadata("kt43159_ArrayUpperBound.kt") + public void testKt43159_ArrayUpperBound() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInIndices/kt43159_ArrayUpperBound.kt"); + } + + @TestMetadata("kt43159_GenericArray.kt") + public void testKt43159_GenericArray() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInIndices/kt43159_GenericArray.kt"); + } } @TestMetadata("compiler/testData/codegen/box/ranges/forInProgressionWithIndex") diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/handlers/IndicesHandlers.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/handlers/IndicesHandlers.kt index fa010712af7..b41176e868b 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/handlers/IndicesHandlers.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/handlers/IndicesHandlers.kt @@ -26,9 +26,8 @@ internal abstract class IndicesHandler(protected val context: CommonBackendConte override fun build(expression: IrCall, data: ProgressionType, scopeOwner: IrSymbol): HeaderInfo? = with(context.createIrBuilder(scopeOwner, expression.startOffset, expression.endOffset)) { // `last = array.size - 1` (last is inclusive) for the loop `for (i in array.indices)`. - val receiver = expression.extensionReceiver!! - val last = irCall(receiver.type.sizePropertyGetter).apply { - dispatchReceiver = receiver + val last = irCall(expression.symbol.owner.extensionReceiverParameter!!.type.sizePropertyGetter).apply { + dispatchReceiver = expression.extensionReceiver!! }.decrement() ProgressionHeaderInfo( diff --git a/compiler/testData/codegen/box/ranges/forInIndices/kt43159_ArrayUpperBound.kt b/compiler/testData/codegen/box/ranges/forInIndices/kt43159_ArrayUpperBound.kt new file mode 100644 index 00000000000..1fe5fc5ec69 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInIndices/kt43159_ArrayUpperBound.kt @@ -0,0 +1,16 @@ +// KJS_WITH_FULL_RUNTIME +// WITH_RUNTIME +// IGNORE_BACKEND: JVM, JVM_IR + +fun test(array: T): Int { + var sum = 0 + for (i in array.indices) { + sum = sum * 10 + i + } + return sum +} + +fun box(): String { + if (test(intArrayOf(0, 0, 0, 0)) != 123) return "fail" + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ranges/forInIndices/kt43159_GenericArray.kt b/compiler/testData/codegen/box/ranges/forInIndices/kt43159_GenericArray.kt new file mode 100644 index 00000000000..c48f80f9caa --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInIndices/kt43159_GenericArray.kt @@ -0,0 +1,19 @@ +// KJS_WITH_FULL_RUNTIME +// WITH_RUNTIME + +class Value(val value: T) { + inline fun runBlock(block: (T) -> R) = block(value) +} + +fun Value>.test() = + runBlock { + var sum = 0 + for (i in it.indices) + sum = sum * 10 + i + sum + } + +fun box(): String { + if (Value>(Array(4) { 0 }).test() != 123) return "fail" + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index f202a39908e..1653ee99af9 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -24343,6 +24343,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { public void testKt13241_Collection() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInIndices/kt13241_Collection.kt"); } + + @TestMetadata("kt43159_ArrayUpperBound.kt") + public void testKt43159_ArrayUpperBound() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInIndices/kt43159_ArrayUpperBound.kt"); + } + + @TestMetadata("kt43159_GenericArray.kt") + public void testKt43159_GenericArray() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInIndices/kt43159_GenericArray.kt"); + } } @TestMetadata("compiler/testData/codegen/box/ranges/forInProgressionWithIndex") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 69301f12925..08d783db24b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -24241,6 +24241,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class ForInIndices extends AbstractLightAnalysisModeTest { + @TestMetadata("kt43159_ArrayUpperBound.kt") + public void ignoreKt43159_ArrayUpperBound() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInIndices/kt43159_ArrayUpperBound.kt"); + } + private void runTest(String testDataFilePath) throws Exception { KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } @@ -24343,6 +24348,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes public void testKt13241_Collection() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInIndices/kt13241_Collection.kt"); } + + @TestMetadata("kt43159_GenericArray.kt") + public void testKt43159_GenericArray() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInIndices/kt43159_GenericArray.kt"); + } } @TestMetadata("compiler/testData/codegen/box/ranges/forInProgressionWithIndex") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 120660ec9ab..0eeba7dda85 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -22572,6 +22572,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes public void testKt13241_Collection() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInIndices/kt13241_Collection.kt"); } + + @TestMetadata("kt43159_ArrayUpperBound.kt") + public void testKt43159_ArrayUpperBound() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInIndices/kt43159_ArrayUpperBound.kt"); + } + + @TestMetadata("kt43159_GenericArray.kt") + public void testKt43159_GenericArray() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInIndices/kt43159_GenericArray.kt"); + } } @TestMetadata("compiler/testData/codegen/box/ranges/forInProgressionWithIndex") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index e2df4a2414b..9d938e7b4e8 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -18793,6 +18793,16 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes public void testKt13241_Collection() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInIndices/kt13241_Collection.kt"); } + + @TestMetadata("kt43159_ArrayUpperBound.kt") + public void testKt43159_ArrayUpperBound() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInIndices/kt43159_ArrayUpperBound.kt"); + } + + @TestMetadata("kt43159_GenericArray.kt") + public void testKt43159_GenericArray() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInIndices/kt43159_GenericArray.kt"); + } } @TestMetadata("compiler/testData/codegen/box/ranges/forInProgressionWithIndex") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 85ffe0ed91a..82c63d0a677 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -18793,6 +18793,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { public void testKt13241_Collection() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInIndices/kt13241_Collection.kt"); } + + @TestMetadata("kt43159_ArrayUpperBound.kt") + public void testKt43159_ArrayUpperBound() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInIndices/kt43159_ArrayUpperBound.kt"); + } + + @TestMetadata("kt43159_GenericArray.kt") + public void testKt43159_GenericArray() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInIndices/kt43159_GenericArray.kt"); + } } @TestMetadata("compiler/testData/codegen/box/ranges/forInProgressionWithIndex") 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 e700002ce15..4b2a245207b 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 @@ -18898,6 +18898,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { public void testKt13241_Collection() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInIndices/kt13241_Collection.kt"); } + + @TestMetadata("kt43159_ArrayUpperBound.kt") + public void testKt43159_ArrayUpperBound() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInIndices/kt43159_ArrayUpperBound.kt"); + } + + @TestMetadata("kt43159_GenericArray.kt") + public void testKt43159_GenericArray() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInIndices/kt43159_GenericArray.kt"); + } } @TestMetadata("compiler/testData/codegen/box/ranges/forInProgressionWithIndex")