KT-47823 IR.JVM Fix handling of for loop ranges with inline types and break/continue/return

This commit is contained in:
Pavel Mikhailovskii
2022-06-08 15:55:11 +02:00
committed by teamcity
parent ecb3cc193c
commit bcd8a28d4c
10 changed files with 63 additions and 0 deletions
@@ -21683,6 +21683,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/inlineClasses/kt47762Generic.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@Test
@TestMetadata("kt47823.kt")
public void testKt47823() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt47823.kt");
}
@Test
@TestMetadata("kt48993.kt")
public void testKt48993() throws Exception {
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrCompositeImpl
import org.jetbrains.kotlin.ir.types.getClass
import org.jetbrains.kotlin.ir.types.isNothing
import org.jetbrains.kotlin.ir.types.isStrictSubtypeOfClass
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.*
@@ -180,6 +181,11 @@ private class RangeLoopTransformer(
val loopHeader = headerProcessor.extractHeader(iteratorVariable)
?: return super.visitBlock(expression.apply { specializeIteratorIfPossible(this) }) // The iterable in the header is not supported.
if (loopHeader.loopInitStatements.any { (it as? IrVariable)?.type?.isNothing() == true }) {
return super.visitBlock(expression)
}
val loweredHeader = lowerHeader(iteratorVariable, loopHeader)
val (newLoop, loopReplacementExpression) = lowerWhileLoop(oldLoop, loopHeader)
+11
View File
@@ -0,0 +1,11 @@
// WITH_STDLIB
fun box(): String {
for (i in 1 .. 2) {
for (j in 1u .. break) {}
}
for (i in 1 .. 2) {
for (j in 1u .. continue) {}
}
for (i in 1u .. return "OK") { }
}
@@ -21203,6 +21203,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/inlineClasses/kt47762Generic.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@Test
@TestMetadata("kt47823.kt")
public void testKt47823() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt47823.kt");
}
@Test
@TestMetadata("kt48993.kt")
public void testKt48993() throws Exception {
@@ -21683,6 +21683,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/inlineClasses/kt47762Generic.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@Test
@TestMetadata("kt47823.kt")
public void testKt47823() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt47823.kt");
}
@Test
@TestMetadata("kt48993.kt")
public void testKt48993() throws Exception {
@@ -17706,6 +17706,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/inlineClasses/kt47762Generic.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
}
@TestMetadata("kt47823.kt")
public void testKt47823() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt47823.kt");
}
@TestMetadata("kt48993.kt")
public void testKt48993() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt48993.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal());
@@ -16723,6 +16723,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/kt47762Generic.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@TestMetadata("kt47823.kt")
public void testKt47823() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt47823.kt");
}
@Test
@TestMetadata("kt51157.kt")
public void testKt51157() throws Exception {
@@ -16687,6 +16687,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/kt47762Generic.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@Test
@TestMetadata("kt47823.kt")
public void testKt47823() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt47823.kt");
}
@Test
@TestMetadata("kt51157.kt")
public void testKt51157() throws Exception {
@@ -14776,6 +14776,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/inlineClasses/kt47762Generic.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation());
}
@TestMetadata("kt47823.kt")
public void testKt47823() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt47823.kt");
}
@TestMetadata("kt51157.kt")
public void testKt51157() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt51157.kt");
@@ -18396,6 +18396,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
runTest("compiler/testData/codegen/box/inlineClasses/kt47762Generic.kt");
}
@Test
@TestMetadata("kt47823.kt")
public void testKt47823() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt47823.kt");
}
@Test
@TestMetadata("kt51157.kt")
public void testKt51157() throws Exception {