diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/RangeCodegenUtil.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/RangeCodegenUtil.kt index d04004f3d62..d54f4fb2b44 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/RangeCodegenUtil.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/RangeCodegenUtil.kt @@ -143,6 +143,12 @@ fun isArrayOrPrimitiveArrayWithIndex(descriptor: CallableDescriptor) = KotlinBuiltIns.isArray(it) || KotlinBuiltIns.isPrimitiveArray(it) } +fun isIterableWithIndex(descriptor: CallableDescriptor) = + descriptor.isTopLevelExtensionOnType("withIndex", "kotlin.collections") { + val typeDescriptor = it.constructor.declarationDescriptor ?: return false + isTopLevelInPackage(typeDescriptor, "Iterable", "kotlin.collections") + } + fun isCollectionIndices(descriptor: CallableDescriptor) = descriptor.isTopLevelExtensionOnType("indices", "kotlin.collections") { KotlinBuiltIns.isCollectionOrNullableCollection(it) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/IterableWithIndexRangeValue.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/IterableWithIndexRangeValue.kt new file mode 100644 index 00000000000..1940022b0e2 --- /dev/null +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/IterableWithIndexRangeValue.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.codegen.range + +import org.jetbrains.kotlin.codegen.ExpressionCodegen +import org.jetbrains.kotlin.codegen.range.forLoop.ForLoopGenerator +import org.jetbrains.kotlin.codegen.range.forLoop.IterableWithIndexForLoopGenerator +import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.psi.KtDestructuringDeclaration +import org.jetbrains.kotlin.psi.KtForExpression +import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall + +class IterableWithIndexRangeValue(rangeCall: ResolvedCall) : AbstractDestructuredPairRangeValue(rangeCall) { + + override fun createDestructuredPairForLoopGenerator( + codegen: ExpressionCodegen, + forExpression: KtForExpression, + loopParameter: KtDestructuringDeclaration, + rangeCall: ResolvedCall + ): ForLoopGenerator = + IterableWithIndexForLoopGenerator(codegen, forExpression, loopParameter, rangeCall) + +} \ No newline at end of file diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/RangeValues.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/RangeValues.kt index 61a71a14fd2..1aaedc9395e 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/RangeValues.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/RangeValues.kt @@ -128,6 +128,8 @@ private fun ExpressionCodegen.createIntrinsifiedRangeValueOrNull(rangeCall: Reso CharSequenceIndicesRangeValue(rangeCall) isArrayOrPrimitiveArrayWithIndex(rangeCallee) -> ArrayWithIndexRangeValue(rangeCall) + isIterableWithIndex(rangeCallee) -> + IterableWithIndexRangeValue(rangeCall) isComparableRangeTo(rangeCallee) -> ComparableRangeLiteralRangeValue(this, rangeCall) isPrimitiveProgressionReverse(rangeCallee) -> diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/IterableWithIndexForLoopGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/IterableWithIndexForLoopGenerator.kt new file mode 100644 index 00000000000..e8774055236 --- /dev/null +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/IterableWithIndexForLoopGenerator.kt @@ -0,0 +1,65 @@ +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.codegen.range.forLoop + +import org.jetbrains.kotlin.codegen.ExpressionCodegen +import org.jetbrains.kotlin.codegen.StackValue +import org.jetbrains.kotlin.codegen.generateCallReceiver +import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.psi.KtDestructuringDeclaration +import org.jetbrains.kotlin.psi.KtForExpression +import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall +import org.jetbrains.kotlin.resolve.jvm.AsmTypes +import org.jetbrains.org.objectweb.asm.Label +import org.jetbrains.org.objectweb.asm.Type + +class IterableWithIndexForLoopGenerator( + codegen: ExpressionCodegen, + forExpression: KtForExpression, + loopParameter: KtDestructuringDeclaration, + rangeCall: ResolvedCall +) : AbstractWithIndexForLoopGenerator(codegen, forExpression, loopParameter, rangeCall) { + private var iteratorVar = -1 + + private var indexVar = -1 + private var indexType = Type.INT_TYPE + + private val asmTypeForIterator = Type.getType(Iterator::class.java) + + override fun beforeLoop() { + indexVar = indexLoopComponent?.parameterVar ?: createLoopTempVariable(Type.INT_TYPE) + indexType = indexLoopComponent?.parameterType ?: Type.INT_TYPE + + StackValue.local(indexVar, indexType) + .store(StackValue.constant(0, Type.INT_TYPE), v) + + iteratorVar = createLoopTempVariable(asmTypeForIterator) + codegen.generateCallReceiver(rangeCall).put(Type.getType(Iterable::class.java), v) + v.invokeinterface("java/lang/Iterable", "iterator", "()Ljava/util/Iterator;") + StackValue.local(iteratorVar, asmTypeForIterator).store(StackValue.onStack(asmTypeForIterator), v) + } + + override fun checkPreCondition(loopExit: Label) { + v.load(iteratorVar, asmTypeForIterator) + v.invokeinterface("java/util/Iterator", "hasNext", "()Z") + v.ifeq(loopExit) + } + + override fun assignLoopParametersNextValues() { + v.load(iteratorVar, asmTypeForIterator) + v.invokeinterface("java/util/Iterator", "next", "()Ljava/lang/Object;") + if (elementLoopComponent != null) { + StackValue.local(elementLoopComponent.parameterVar, elementLoopComponent.parameterType) + .store(StackValue.onStack(AsmTypes.OBJECT_TYPE), v) + } else { + v.pop() + } + } + + override fun incrementAndCheckPostCondition(loopExit: Label) { + v.iinc(indexVar, 1) + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInEmptyListWithIndex.kt b/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInEmptyListWithIndex.kt new file mode 100644 index 00000000000..153bb11f7eb --- /dev/null +++ b/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInEmptyListWithIndex.kt @@ -0,0 +1,11 @@ +// WITH_RUNTIME + +val xs = listOf() + +fun box(): String { + val s = StringBuilder() + for ((index, x) in xs.withIndex()) { + return "Loop over empty list should not be executed" + } + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndex.kt b/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndex.kt new file mode 100644 index 00000000000..fd529f7561e --- /dev/null +++ b/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndex.kt @@ -0,0 +1,14 @@ +// WITH_RUNTIME + +val xs = listOf("a", "b", "c", "d") + +fun box(): String { + val s = StringBuilder() + + for ((index, x) in xs.withIndex()) { + s.append("$index:$x;") + } + + val ss = s.toString() + return if (ss == "0:a;1:b;2:c;3:d;") "OK" else "fail: '$ss'" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexNoElementVar.kt b/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexNoElementVar.kt new file mode 100644 index 00000000000..a442bce6cf0 --- /dev/null +++ b/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexNoElementVar.kt @@ -0,0 +1,14 @@ +// WITH_RUNTIME + +val xs = listOf("a", "b", "c", "d") + +fun box(): String { + val s = StringBuilder() + + for ((i, _) in xs.withIndex()) { + s.append("$i;") + } + + val ss = s.toString() + return if (ss == "0;1;2;3;") "OK" else "fail: '$ss'" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexNoIndexVar.kt b/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexNoIndexVar.kt new file mode 100644 index 00000000000..e38b740c350 --- /dev/null +++ b/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexNoIndexVar.kt @@ -0,0 +1,14 @@ +// WITH_RUNTIME + +val xs = listOf("a", "b", "c", "d") + +fun box(): String { + val s = StringBuilder() + + for ((_, x) in xs.withIndex()) { + s.append("$x;") + } + + val ss = s.toString() + return if (ss == "a;b;c;d;") "OK" else "fail: '$ss'" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexThrowsCME.kt b/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexThrowsCME.kt new file mode 100644 index 00000000000..312d094c348 --- /dev/null +++ b/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexThrowsCME.kt @@ -0,0 +1,24 @@ +// IGNORE_BACKEND: JS, NATIVE +// FULL_JDK +// WITH_RUNTIME + +val xs = arrayListOf("a", "b", "c", "d") + +fun box(): String { + val s = StringBuilder() + + var cmeThrown = false + try { + for ((index, x) in xs.withIndex()) { + s.append("$index:$x;") + xs.clear() + } + } catch (e: java.util.ConcurrentModificationException) { + cmeThrown = true + } + + if (!cmeThrown) return "Fail: CME should be thrown" + + val ss = s.toString() + return if (ss == "0:a;") "OK" else "fail: '$ss'" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexWithExplicitlyTypedIndexVariable.kt b/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexWithExplicitlyTypedIndexVariable.kt new file mode 100644 index 00000000000..6ecc9408208 --- /dev/null +++ b/compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexWithExplicitlyTypedIndexVariable.kt @@ -0,0 +1,17 @@ +// WITH_RUNTIME + +val xs = listOf("a", "b", "c", "d") + +fun useAny(x: Any) {} + +fun box(): String { + val s = StringBuilder() + + for ((index: Any, x) in xs.withIndex()) { + useAny(index) + s.append("$index:$x;") + } + + val ss = s.toString() + return if (ss == "0:a;1:b;2:c;3:d;") "OK" else "fail: '$ss'" +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInEmptyListWithIndex.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInEmptyListWithIndex.kt new file mode 100644 index 00000000000..c34804b0469 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInEmptyListWithIndex.kt @@ -0,0 +1,18 @@ +// WITH_RUNTIME + +val xs = listOf() + +fun box(): String { + val s = StringBuilder() + for ((index, x) in xs.withIndex()) { + return "Loop over empty array should not be executed" + } + return "OK" +} + +// 0 withIndex +// 1 iterator +// 1 hasNext +// 1 next +// 0 component1 +// 0 component2 \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndex.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndex.kt new file mode 100644 index 00000000000..4824f633a68 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndex.kt @@ -0,0 +1,21 @@ +// WITH_RUNTIME + +val xs = listOf("a", "b", "c", "d") + +fun box(): String { + val s = StringBuilder() + + for ((index, x) in xs.withIndex()) { + s.append("$index:$x;") + } + + val ss = s.toString() + return if (ss == "0:a;1:b;2:c;3:d;") "OK" else "fail: '$ss'" +} + +// 0 withIndex +// 1 iterator +// 1 hasNext +// 1 next +// 0 component1 +// 0 component2 \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexNoElementVar.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexNoElementVar.kt new file mode 100644 index 00000000000..29e823d376c --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexNoElementVar.kt @@ -0,0 +1,21 @@ +// WITH_RUNTIME + +val xs = listOf("a", "b", "c", "d") + +fun box(): String { + val s = StringBuilder() + + for ((i, _) in xs.withIndex()) { + s.append("$i;") + } + + val ss = s.toString() + return if (ss == "0;1;2;3;") "OK" else "fail: '$ss'" +} + +// 0 withIndex +// 1 iterator +// 1 hasNext +// 1 next +// 0 component1 +// 0 component2 \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexNoIndexVar.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexNoIndexVar.kt new file mode 100644 index 00000000000..2115a067c1c --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexNoIndexVar.kt @@ -0,0 +1,21 @@ +// WITH_RUNTIME + +val xs = listOf("a", "b", "c", "d") + +fun box(): String { + val s = StringBuilder() + + for ((_, x) in xs.withIndex()) { + s.append("$x;") + } + + val ss = s.toString() + return if (ss == "a;b;c;d;") "OK" else "fail: '$ss'" +} + +// 0 withIndex +// 1 iterator +// 1 hasNext +// 1 next +// 0 component1 +// 0 component2 \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexWithExplicitlyTypedIndexVariable.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexWithExplicitlyTypedIndexVariable.kt new file mode 100644 index 00000000000..6abe341f2f9 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexWithExplicitlyTypedIndexVariable.kt @@ -0,0 +1,24 @@ +// WITH_RUNTIME + +val xs = listOf("a", "b", "c", "d") + +fun useAny(x: Any) {} + +fun box(): String { + val s = StringBuilder() + + for ((index: Any, x) in xs.withIndex()) { + useAny(index) + s.append("$index:$x;") + } + + val ss = s.toString() + return if (ss == "0:a;1:b;2:c;3:d;") "OK" else "fail: '$ss'" +} + +// 0 withIndex +// 1 iterator +// 1 hasNext +// 1 next +// 0 component1 +// 0 component2 \ No newline at end of file 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 5c3509cc4d0..75c9bfec71a 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 @@ -5223,6 +5223,51 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes } } + @TestMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ForInIterableWithIndex extends AbstractIrBlackBoxCodegenTest { + public void testAllFilesPresentInForInIterableWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("forInEmptyListWithIndex.kt") + public void testForInEmptyListWithIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInEmptyListWithIndex.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndex.kt") + public void testForInListWithIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndex.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexNoElementVar.kt") + public void testForInListWithIndexNoElementVar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexNoElementVar.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexNoIndexVar.kt") + public void testForInListWithIndexNoIndexVar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexNoIndexVar.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexThrowsCME.kt") + public void testForInListWithIndexThrowsCME() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexThrowsCME.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexWithExplicitlyTypedIndexVariable.kt") + public void testForInListWithIndexWithExplicitlyTypedIndexVariable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexWithExplicitlyTypedIndexVariable.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/controlStructures/returnsNothing") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 9237b06e282..26c55f7978e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -5223,6 +5223,51 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } } + @TestMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ForInIterableWithIndex extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInForInIterableWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("forInEmptyListWithIndex.kt") + public void testForInEmptyListWithIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInEmptyListWithIndex.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndex.kt") + public void testForInListWithIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndex.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexNoElementVar.kt") + public void testForInListWithIndexNoElementVar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexNoElementVar.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexNoIndexVar.kt") + public void testForInListWithIndexNoIndexVar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexNoIndexVar.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexThrowsCME.kt") + public void testForInListWithIndexThrowsCME() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexThrowsCME.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexWithExplicitlyTypedIndexVariable.kt") + public void testForInListWithIndexWithExplicitlyTypedIndexVariable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexWithExplicitlyTypedIndexVariable.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/controlStructures/returnsNothing") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index cca83afb5e5..39353f2f830 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -1452,6 +1452,45 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { } } + @TestMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ForInIterableWithIndex extends AbstractBytecodeTextTest { + public void testAllFilesPresentInForInIterableWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("forInEmptyListWithIndex.kt") + public void testForInEmptyListWithIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInEmptyListWithIndex.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndex.kt") + public void testForInListWithIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndex.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexNoElementVar.kt") + public void testForInListWithIndexNoElementVar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexNoElementVar.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexNoIndexVar.kt") + public void testForInListWithIndexNoIndexVar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexNoIndexVar.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexWithExplicitlyTypedIndexVariable.kt") + public void testForInListWithIndexWithExplicitlyTypedIndexVariable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInIterableWithIndex/forInListWithIndexWithExplicitlyTypedIndexVariable.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInReversed") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 9407e571f9b..92965ca2760 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -5223,6 +5223,51 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes } } + @TestMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ForInIterableWithIndex extends AbstractLightAnalysisModeTest { + public void testAllFilesPresentInForInIterableWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("forInEmptyListWithIndex.kt") + public void testForInEmptyListWithIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInEmptyListWithIndex.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndex.kt") + public void testForInListWithIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndex.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexNoElementVar.kt") + public void testForInListWithIndexNoElementVar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexNoElementVar.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexNoIndexVar.kt") + public void testForInListWithIndexNoIndexVar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexNoIndexVar.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexThrowsCME.kt") + public void testForInListWithIndexThrowsCME() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexThrowsCME.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexWithExplicitlyTypedIndexVariable.kt") + public void testForInListWithIndexWithExplicitlyTypedIndexVariable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexWithExplicitlyTypedIndexVariable.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/controlStructures/returnsNothing") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) 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 9b599b46aac..8ad284caf2e 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 @@ -5805,6 +5805,57 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ForInIterableWithIndex extends AbstractJsCodegenBoxTest { + public void testAllFilesPresentInForInIterableWithIndex() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); + } + + @TestMetadata("forInEmptyListWithIndex.kt") + public void testForInEmptyListWithIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInEmptyListWithIndex.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndex.kt") + public void testForInListWithIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndex.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexNoElementVar.kt") + public void testForInListWithIndexNoElementVar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexNoElementVar.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexNoIndexVar.kt") + public void testForInListWithIndexNoIndexVar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexNoIndexVar.kt"); + doTest(fileName); + } + + @TestMetadata("forInListWithIndexThrowsCME.kt") + public void testForInListWithIndexThrowsCME() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexThrowsCME.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("forInListWithIndexWithExplicitlyTypedIndexVariable.kt") + public void testForInListWithIndexWithExplicitlyTypedIndexVariable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInIterableWithIndex/forInListWithIndexWithExplicitlyTypedIndexVariable.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/controlStructures/returnsNothing") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)