PSI2IR KT-47245 handle declaration statements in control structures

This commit is contained in:
Dmitry Petrov
2021-06-11 13:24:35 +03:00
committed by TeamCityServer
parent 3be348f910
commit bf077b893c
15 changed files with 120 additions and 2 deletions
@@ -7944,6 +7944,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/controlStructures/kt42455.kt");
}
@Test
@TestMetadata("kt47245.kt")
public void testKt47245() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/kt47245.kt");
}
@Test
@TestMetadata("kt513.kt")
public void testKt513() throws Exception {
@@ -1406,6 +1406,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
runTest("compiler/testData/ir/irText/expressions/kt47082.kt");
}
@Test
@TestMetadata("kt47245.kt")
public void testKt47245() throws Exception {
runTest("compiler/testData/ir/irText/expressions/kt47245.kt");
}
@Test
@TestMetadata("lambdaInCAO.kt")
public void testLambdaInCAO() throws Exception {
@@ -22,13 +22,14 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.assertCast
import org.jetbrains.kotlin.ir.builders.Scope
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.util.referenceFunction
import org.jetbrains.kotlin.ir.util.render
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.startOffsetSkippingComments
@@ -84,7 +85,20 @@ class StatementGenerator(
}
private fun KtElement.genExpr(): IrExpression =
genStmt().assertCast()
when (val irStatement = genStmt()) {
is IrExpression ->
irStatement
is IrDeclaration ->
IrBlockImpl(
irStatement.startOffset,
irStatement.endOffset,
this@StatementGenerator.context.irBuiltIns.unitType,
null,
listOf(irStatement)
)
else ->
throw AssertionError("Unexpected statement: ${irStatement.render()}")
}
override fun visitExpression(expression: KtExpression, data: Nothing?): IrStatement =
IrErrorExpressionImpl(
@@ -0,0 +1,6 @@
// IGNORE_BACKEND: JVM
fun box(): String {
for (i in 0..0) fun x() {}
return "OK"
}
+19
View File
@@ -0,0 +1,19 @@
FILE fqName:<root> fileName:/kt47245.kt
FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
BLOCK type=kotlin.Unit origin=FOR_LOOP
VAR FOR_LOOP_ITERATOR name:tmp_0 type:kotlin.collections.IntIterator [val]
CALL 'public open fun iterator (): kotlin.collections.IntIterator [operator] declared in kotlin.ranges.IntProgression' type=kotlin.collections.IntIterator origin=FOR_LOOP_ITERATOR
$this: CALL 'public final fun rangeTo (other: kotlin.Int): kotlin.ranges.IntRange [operator] declared in kotlin.Int' type=kotlin.ranges.IntRange origin=RANGE
$this: CONST Int type=kotlin.Int value=0
other: CONST Int type=kotlin.Int value=0
WHILE label=null origin=FOR_LOOP_INNER_WHILE
condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
$this: GET_VAR 'val tmp_0: kotlin.collections.IntIterator [val] declared in <root>.test' type=kotlin.collections.IntIterator origin=null
body: BLOCK type=kotlin.Unit origin=FOR_LOOP_INNER_WHILE
VAR FOR_LOOP_VARIABLE name:i type:kotlin.Int [val]
CALL 'public final fun next (): kotlin.Int [operator] declared in kotlin.collections.IntIterator' type=kotlin.Int origin=FOR_LOOP_NEXT
$this: GET_VAR 'val tmp_0: kotlin.collections.IntIterator [val] declared in <root>.test' type=kotlin.collections.IntIterator origin=null
BLOCK type=kotlin.Unit origin=null
FUN name:x visibility:local modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
+5
View File
@@ -0,0 +1,5 @@
// SKIP_KT_DUMP
fun test() {
for (i in 0..0) fun x() {}
}
+19
View File
@@ -0,0 +1,19 @@
FILE fqName:<root> fileName:/kt47245.kt
FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
BLOCK type=kotlin.Unit origin=FOR_LOOP
VAR FOR_LOOP_ITERATOR name:tmp_0 type:kotlin.collections.IntIterator [val]
CALL 'public open fun iterator (): kotlin.collections.IntIterator [fake_override,operator] declared in kotlin.ranges.IntRange' type=kotlin.collections.IntIterator origin=FOR_LOOP_ITERATOR
$this: CALL 'public final fun rangeTo (other: kotlin.Int): kotlin.ranges.IntRange [operator] declared in kotlin.Int' type=kotlin.ranges.IntRange origin=RANGE
$this: CONST Int type=kotlin.Int value=0
other: CONST Int type=kotlin.Int value=0
WHILE label=null origin=FOR_LOOP_INNER_WHILE
condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [fake_override,operator] declared in kotlin.collections.IntIterator' type=kotlin.Boolean origin=FOR_LOOP_HAS_NEXT
$this: GET_VAR 'val tmp_0: kotlin.collections.IntIterator [val] declared in <root>.test' type=kotlin.collections.IntIterator origin=null
body: BLOCK type=kotlin.Unit origin=FOR_LOOP_INNER_WHILE
VAR FOR_LOOP_VARIABLE name:i type:kotlin.Int [val]
CALL 'public final fun next (): kotlin.Int [operator] declared in kotlin.collections.IntIterator' type=kotlin.Int origin=FOR_LOOP_NEXT
$this: GET_VAR 'val tmp_0: kotlin.collections.IntIterator [val] declared in <root>.test' type=kotlin.collections.IntIterator origin=null
BLOCK type=kotlin.Unit origin=null
FUN name:x visibility:local modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
@@ -7944,6 +7944,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/controlStructures/kt42455.kt");
}
@Test
@TestMetadata("kt47245.kt")
public void testKt47245() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/kt47245.kt");
}
@Test
@TestMetadata("kt513.kt")
public void testKt513() throws Exception {
@@ -7944,6 +7944,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/controlStructures/kt42455.kt");
}
@Test
@TestMetadata("kt47245.kt")
public void testKt47245() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/kt47245.kt");
}
@Test
@TestMetadata("kt513.kt")
public void testKt513() throws Exception {
@@ -1406,6 +1406,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest {
runTest("compiler/testData/ir/irText/expressions/kt47082.kt");
}
@Test
@TestMetadata("kt47245.kt")
public void testKt47245() throws Exception {
runTest("compiler/testData/ir/irText/expressions/kt47245.kt");
}
@Test
@TestMetadata("lambdaInCAO.kt")
public void testLambdaInCAO() throws Exception {
@@ -5769,6 +5769,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ControlStructures extends AbstractLightAnalysisModeTest {
@TestMetadata("kt47245.kt")
public void ignoreKt47245() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/kt47245.kt");
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
@@ -5351,6 +5351,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/controlStructures/kt42455.kt");
}
@TestMetadata("kt47245.kt")
public void testKt47245() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/kt47245.kt");
}
@TestMetadata("kt513.kt")
public void testKt513() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/kt513.kt");
@@ -4757,6 +4757,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/controlStructures/kt42455.kt");
}
@TestMetadata("kt47245.kt")
public void testKt47245() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/kt47245.kt");
}
@TestMetadata("kt513.kt")
public void testKt513() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/kt513.kt");
@@ -4757,6 +4757,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/controlStructures/kt42455.kt");
}
@TestMetadata("kt47245.kt")
public void testKt47245() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/kt47245.kt");
}
@TestMetadata("kt513.kt")
public void testKt513() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/kt513.kt");
@@ -3365,6 +3365,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/controlStructures/kt42455.kt");
}
@TestMetadata("kt47245.kt")
public void testKt47245() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/kt47245.kt");
}
@TestMetadata("kt772.kt")
public void testKt772() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/kt772.kt");