From 0da4b060740feba4b89ba5ccd9a55f0788cb2d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20Sch=C3=A4fer?= Date: Thu, 24 Oct 2019 09:50:50 +0200 Subject: [PATCH] psi2ir: Fix return insertion We should only insert a return statement at the end of a lambda or function if the final statement is used as an expression (slice USED_AS_RESULT_OF_LAMBDA and USED_AS_EXPRESSION). --- .../kotlin/fir/Fir2IrTextTestGenerated.java | 5 +++ .../kotlin/psi2ir/generators/BodyGenerator.kt | 39 +++++++++---------- .../boxInline/smap/anonymous/lambda.kt | 2 +- .../boxInline/smap/anonymous/object.kt | 2 +- .../smap/newsmap/mappingInInlineFunLambda.kt | 2 +- .../expressions/argumentMappedWithError.txt | 3 +- .../ir/irText/expressions/coercionToUnit.txt | 5 +-- .../enumEntryReferenceFromEnumEntryClass.txt | 5 +-- .../ir/irText/expressions/objectReference.txt | 5 +-- .../irText/expressions/sam/samConversions.txt | 6 +-- .../irText/expressions/whenReturnUnit.fir.txt | 27 +++++++++++++ .../ir/irText/expressions/whenReturnUnit.kt | 8 ++++ .../ir/irText/expressions/whenReturnUnit.txt | 28 +++++++++++++ .../ir/irText/lambdas/nonLocalReturn.txt | 25 ++++++------ .../testData/ir/irText/lambdas/samAdapter.txt | 5 +-- .../irText/regressions/integerCoercionToT.txt | 6 +-- .../newInference/fixationOrder1.txt | 6 +-- .../testData/ir/irText/stubs/builtinMap.txt | 15 ++++--- .../kotlin/ir/IrTextTestCaseGenerated.java | 5 +++ 19 files changed, 127 insertions(+), 72 deletions(-) create mode 100644 compiler/testData/ir/irText/expressions/whenReturnUnit.fir.txt create mode 100644 compiler/testData/ir/irText/expressions/whenReturnUnit.kt create mode 100644 compiler/testData/ir/irText/expressions/whenReturnUnit.txt diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java index 9cb8130eaad..ff09f5b09cb 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java @@ -1286,6 +1286,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/expressions/whenReturn.kt"); } + @TestMetadata("whenReturnUnit.kt") + public void testWhenReturnUnit() throws Exception { + runTest("compiler/testData/ir/irText/expressions/whenReturnUnit.kt"); + } + @TestMetadata("whenUnusedExpression.kt") public void testWhenUnusedExpression() throws Exception { runTest("compiler/testData/ir/irText/expressions/whenUnusedExpression.kt"); diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BodyGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BodyGenerator.kt index 81e5d1b44b2..d28429a73ae 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BodyGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BodyGenerator.kt @@ -31,6 +31,8 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffsetSkippingComments import org.jetbrains.kotlin.psi.synthetics.findClassDescriptor import org.jetbrains.kotlin.psi2ir.intermediate.VariableLValue import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression +import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsResultOfLambda import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassOrAny import org.jetbrains.kotlin.types.KotlinType @@ -56,7 +58,13 @@ class BodyGenerator( if (ktBody is KtBlockExpression) { statementGenerator.generateStatements(ktBody.statements, irBlockBody) } else { - statementGenerator.generateReturnExpression(ktBody, irBlockBody) + val irBody = statementGenerator.generateStatement(ktBody) + irBlockBody.statements.add( + if (ktBody.isUsedAsExpression(context.bindingContext) && irBody is IrExpression) + generateReturnExpression(irBody.startOffset, irBody.endOffset, irBody) + else + irBody + ) } return irBlockBody @@ -90,7 +98,14 @@ class BodyGenerator( irBlockBody.statements.add(statementGenerator.generateStatement(ktStatement)) } val ktReturnedValue = ktBodyStatements.last() - statementGenerator.generateReturnExpression(ktReturnedValue, irBlockBody) + val irReturnedValue = statementGenerator.generateStatement(ktReturnedValue) + irBlockBody.statements.add( + if (ktReturnedValue.isUsedAsResultOfLambda(context.bindingContext) && irReturnedValue is IrExpression) { + generateReturnExpression(irReturnedValue.startOffset, irReturnedValue.endOffset, irReturnedValue) + } else { + irReturnedValue + } + ) } else { irBlockBody.statements.add( generateReturnExpression( @@ -106,23 +121,6 @@ class BodyGenerator( return irBlockBody } - private fun StatementGenerator.generateReturnExpression(ktExpression: KtExpression, irBlockBody: IrBlockBodyImpl) { - val irReturnExpression = generateStatement(ktExpression) - if (irReturnExpression is IrExpression) { - irBlockBody.statements.add(irReturnExpression.wrapWithReturn()) - } else { - irBlockBody.statements.add(irReturnExpression) - } - } - - private fun IrExpression.wrapWithReturn() = - if (this is IrReturn || this is IrErrorExpression || this is IrThrow) - this - else { - generateReturnExpression(startOffset, endOffset, this) - } - - private fun generateReturnExpression(startOffset: Int, endOffset: Int, returnValue: IrExpression): IrReturnImpl { val returnTarget = (scopeOwner as? CallableDescriptor) ?: throw AssertionError("'return' in a non-callable: $scopeOwner") return IrReturnImpl( @@ -132,7 +130,6 @@ class BodyGenerator( ) } - fun generateSecondaryConstructorBody(ktConstructor: KtSecondaryConstructor): IrBody { val irBlockBody = IrBlockBodyImpl(ktConstructor.startOffsetSkippingComments, ktConstructor.endOffset) @@ -319,7 +316,7 @@ class BodyGenerator( } val enumDefaultConstructorCall = getResolvedCall(ktEnumEntry) - ?: throw AssertionError("No default constructor call for enum entry $enumClassDescriptor") + ?: throw AssertionError("No default constructor call for enum entry $enumClassDescriptor") return statementGenerator.generateEnumConstructorCall(enumDefaultConstructorCall, ktEnumEntry) } diff --git a/compiler/testData/codegen/boxInline/smap/anonymous/lambda.kt b/compiler/testData/codegen/boxInline/smap/anonymous/lambda.kt index d4fbd3a71af..652017a989c 100644 --- a/compiler/testData/codegen/boxInline/smap/anonymous/lambda.kt +++ b/compiler/testData/codegen/boxInline/smap/anonymous/lambda.kt @@ -1,4 +1,4 @@ -// IGNORE_BACKEND_MULTI_MODULE: JVM_IR + // FILE: 1.kt package builders diff --git a/compiler/testData/codegen/boxInline/smap/anonymous/object.kt b/compiler/testData/codegen/boxInline/smap/anonymous/object.kt index e8b0090c435..abda5de5a05 100644 --- a/compiler/testData/codegen/boxInline/smap/anonymous/object.kt +++ b/compiler/testData/codegen/boxInline/smap/anonymous/object.kt @@ -1,6 +1,6 @@ // FILE: 1.kt -// IGNORE_BACKEND_MULTI_MODULE: JVM_IR + package builders inline fun call(crossinline init: () -> Unit) { diff --git a/compiler/testData/codegen/boxInline/smap/newsmap/mappingInInlineFunLambda.kt b/compiler/testData/codegen/boxInline/smap/newsmap/mappingInInlineFunLambda.kt index 4cc1ad72fe5..c40b1c7a80e 100644 --- a/compiler/testData/codegen/boxInline/smap/newsmap/mappingInInlineFunLambda.kt +++ b/compiler/testData/codegen/boxInline/smap/newsmap/mappingInInlineFunLambda.kt @@ -1,4 +1,4 @@ -// IGNORE_BACKEND_MULTI_MODULE: JVM_IR + // FILE: 1.kt package test diff --git a/compiler/testData/ir/irText/expressions/argumentMappedWithError.txt b/compiler/testData/ir/irText/expressions/argumentMappedWithError.txt index d2c6c274f9c..ad3315b341a 100644 --- a/compiler/testData/ir/irText/expressions/argumentMappedWithError.txt +++ b/compiler/testData/ir/irText/expressions/argumentMappedWithError.txt @@ -3,8 +3,7 @@ FILE fqName: fileName:/argumentMappedWithError.kt TYPE_PARAMETER name:R index:0 variance: superTypes:[kotlin.Number] $receiver: VALUE_PARAMETER name: type:kotlin.Number BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun convert (): R of .convert declared in ' - CALL 'public final fun TODO (): kotlin.Nothing [inline] declared in kotlin' type=kotlin.Nothing origin=null + CALL 'public final fun TODO (): kotlin.Nothing [inline] declared in kotlin' type=kotlin.Nothing origin=null FUN name:foo visibility:public modality:FINAL <> (arg:kotlin.Number) returnType:kotlin.Unit VALUE_PARAMETER name:arg index:0 type:kotlin.Number BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/coercionToUnit.txt b/compiler/testData/ir/irText/expressions/coercionToUnit.txt index c99287745e8..287681d516a 100644 --- a/compiler/testData/ir/irText/expressions/coercionToUnit.txt +++ b/compiler/testData/ir/irText/expressions/coercionToUnit.txt @@ -5,9 +5,8 @@ FILE fqName: fileName:/coercionToUnit.kt FUN_EXPR type=kotlin.Function0 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .test1' - TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit - CONST Int type=kotlin.Int value=42 + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CONST Int type=kotlin.Int value=42 FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.Function0 correspondingProperty: PROPERTY name:test1 visibility:public modality:FINAL [val] BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/enumEntryReferenceFromEnumEntryClass.txt b/compiler/testData/ir/irText/expressions/enumEntryReferenceFromEnumEntryClass.txt index ddd44e45ae8..f330fccf139 100644 --- a/compiler/testData/ir/irText/expressions/enumEntryReferenceFromEnumEntryClass.txt +++ b/compiler/testData/ir/irText/expressions/enumEntryReferenceFromEnumEntryClass.txt @@ -53,9 +53,8 @@ FILE fqName: fileName:/enumEntryReferenceFromEnumEntryClass.kt CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .MyEnum.Z' type=kotlin.Unit origin=EQ $this: GET_ENUM 'ENUM_ENTRY name:Z' type=.MyEnum.Z : CONST Int type=kotlin.Int value=1 - RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .MyEnum.Z.aLambda' - CALL 'public final fun foo (): kotlin.Unit declared in .MyEnum.Z' type=kotlin.Unit origin=null - $this: GET_ENUM 'ENUM_ENTRY name:Z' type=.MyEnum.Z + CALL 'public final fun foo (): kotlin.Unit declared in .MyEnum.Z' type=kotlin.Unit origin=null + $this: GET_ENUM 'ENUM_ENTRY name:Z' type=.MyEnum.Z FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.MyEnum.Z) returnType:kotlin.Function0 correspondingProperty: PROPERTY name:aLambda visibility:public modality:FINAL [val] $this: VALUE_PARAMETER name: type:.MyEnum.Z diff --git a/compiler/testData/ir/irText/expressions/objectReference.txt b/compiler/testData/ir/irText/expressions/objectReference.txt index b5bd60ab3dd..f049297bfdc 100644 --- a/compiler/testData/ir/irText/expressions/objectReference.txt +++ b/compiler/testData/ir/irText/expressions/objectReference.txt @@ -98,9 +98,8 @@ FILE fqName: fileName:/objectReference.kt CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .Z' type=kotlin.Unit origin=EQ $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z : CONST Int type=kotlin.Int value=1 - RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .Z.aLambda' - CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z + CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null + $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Z) returnType:kotlin.Function0 correspondingProperty: PROPERTY name:aLambda visibility:public modality:FINAL [val] $this: VALUE_PARAMETER name: type:.Z diff --git a/compiler/testData/ir/irText/expressions/sam/samConversions.txt b/compiler/testData/ir/irText/expressions/sam/samConversions.txt index a3f301fa867..f73745b3804 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversions.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConversions.txt @@ -15,8 +15,7 @@ FILE fqName: fileName:/samConversions.kt FUN_EXPR type=kotlin.Function0 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .test1' - CALL 'public final fun test1 (): kotlin.Unit declared in ' type=kotlin.Unit origin=null + CALL 'public final fun test1 (): kotlin.Unit declared in ' type=kotlin.Unit origin=null FUN name:test2 visibility:public modality:FINAL <> ($receiver:.J) returnType:kotlin.Unit $receiver: VALUE_PARAMETER name: type:.J BLOCK_BODY @@ -26,8 +25,7 @@ FILE fqName: fileName:/samConversions.kt FUN_EXPR type=kotlin.Function0 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .test2' - CALL 'public final fun test1 (): kotlin.Unit declared in ' type=kotlin.Unit origin=null + CALL 'public final fun test1 (): kotlin.Unit declared in ' type=kotlin.Unit origin=null FUN name:test3 visibility:public modality:FINAL <> ($receiver:.J, a:kotlin.Function0) returnType:kotlin.Unit $receiver: VALUE_PARAMETER name: type:.J VALUE_PARAMETER name:a index:0 type:kotlin.Function0 diff --git a/compiler/testData/ir/irText/expressions/whenReturnUnit.fir.txt b/compiler/testData/ir/irText/expressions/whenReturnUnit.fir.txt new file mode 100644 index 00000000000..cbeb296f25d --- /dev/null +++ b/compiler/testData/ir/irText/expressions/whenReturnUnit.fir.txt @@ -0,0 +1,27 @@ +FILE fqName: fileName:/whenReturnUnit.kt + FUN name:run visibility:public modality:FINAL <> (block:kotlin.Function0) returnType:kotlin.Unit + VALUE_PARAMETER name:block index:0 type:kotlin.Function0 + BLOCK_BODY + FUN name:branch visibility:public modality:FINAL <> (x:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER name:x index:0 type:kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun branch (x: kotlin.Int): kotlin.Unit declared in ' + CALL 'public final fun run (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + BLOCK type=kotlin.Unit origin=WHEN + VAR IR_TEMPORARY_VARIABLE name:tmp0_subject type:kotlin.Int [val] + WHEN type=kotlin.Unit origin=WHEN + BRANCH + if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ + arg0: GET_VAR 'val tmp0_subject: kotlin.Int [val] declared in .branch.' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=1 + then: CALL 'public final fun TODO (reason: kotlin.String): kotlin.Nothing [inline] declared in kotlin' type=kotlin.Nothing origin=null + reason: CONST String type=kotlin.String value="1" + BRANCH + if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ + arg0: GET_VAR 'val tmp0_subject: kotlin.Int [val] declared in .branch.' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=2 + then: CALL 'public final fun TODO (reason: kotlin.String): kotlin.Nothing [inline] declared in kotlin' type=kotlin.Nothing origin=null + reason: CONST String type=kotlin.String value="2" diff --git a/compiler/testData/ir/irText/expressions/whenReturnUnit.kt b/compiler/testData/ir/irText/expressions/whenReturnUnit.kt new file mode 100644 index 00000000000..93722a87b99 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/whenReturnUnit.kt @@ -0,0 +1,8 @@ +fun run(block: () -> Unit) {} + +fun branch(x: Int) = run { + when (x) { + 1 -> TODO("1") + 2 -> TODO("2") + } +} diff --git a/compiler/testData/ir/irText/expressions/whenReturnUnit.txt b/compiler/testData/ir/irText/expressions/whenReturnUnit.txt new file mode 100644 index 00000000000..bb41f5a63c8 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/whenReturnUnit.txt @@ -0,0 +1,28 @@ +FILE fqName: fileName:/whenReturnUnit.kt + FUN name:run visibility:public modality:FINAL <> (block:kotlin.Function0) returnType:kotlin.Unit + VALUE_PARAMETER name:block index:0 type:kotlin.Function0 + BLOCK_BODY + FUN name:branch visibility:public modality:FINAL <> (x:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER name:x index:0 type:kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun branch (x: kotlin.Int): kotlin.Unit declared in ' + CALL 'public final fun run (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + BLOCK type=kotlin.Nothing origin=WHEN + VAR IR_TEMPORARY_VARIABLE name:tmp0_subject type:kotlin.Int [val] + GET_VAR 'x: kotlin.Int declared in .branch' type=kotlin.Int origin=null + WHEN type=kotlin.Nothing origin=WHEN + BRANCH + if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ + arg0: GET_VAR 'val tmp0_subject: kotlin.Int [val] declared in .branch.' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=1 + then: CALL 'public final fun TODO (reason: kotlin.String): kotlin.Nothing [inline] declared in kotlin' type=kotlin.Nothing origin=null + reason: CONST String type=kotlin.String value="1" + BRANCH + if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ + arg0: GET_VAR 'val tmp0_subject: kotlin.Int [val] declared in .branch.' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=2 + then: CALL 'public final fun TODO (reason: kotlin.String): kotlin.Nothing [inline] declared in kotlin' type=kotlin.Nothing origin=null + reason: CONST String type=kotlin.String value="2" diff --git a/compiler/testData/ir/irText/lambdas/nonLocalReturn.txt b/compiler/testData/ir/irText/lambdas/nonLocalReturn.txt index 3d1e34694e8..80eec40ce6c 100644 --- a/compiler/testData/ir/irText/lambdas/nonLocalReturn.txt +++ b/compiler/testData/ir/irText/lambdas/nonLocalReturn.txt @@ -33,14 +33,13 @@ FILE fqName: fileName:/nonLocalReturn.kt block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .test3' - CALL 'public final fun run (block: kotlin.Function0): R of kotlin.run [inline] declared in kotlin' type=kotlin.Nothing origin=null - : kotlin.Nothing - block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Nothing - BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .test3' - GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + CALL 'public final fun run (block: kotlin.Function0): R of kotlin.run [inline] declared in kotlin' type=kotlin.Nothing origin=null + : kotlin.Nothing + block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Nothing + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .test3' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit FUN name:testLrmFoo1 visibility:public modality:FINAL <> (ints:kotlin.collections.List) returnType:kotlin.Unit VALUE_PARAMETER name:ints index:0 type:kotlin.collections.List BLOCK_BODY @@ -58,9 +57,8 @@ FILE fqName: fileName:/nonLocalReturn.kt arg1: CONST Int type=kotlin.Int value=0 then: RETURN type=kotlin.Nothing from='local final fun (it: kotlin.Int): kotlin.Unit declared in .testLrmFoo1' GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit - RETURN type=kotlin.Nothing from='local final fun (it: kotlin.Int): kotlin.Unit declared in .testLrmFoo1' - CALL 'public final fun print (message: kotlin.Int): kotlin.Unit [inline] declared in kotlin.io' type=kotlin.Unit origin=null - message: GET_VAR 'it: kotlin.Int declared in .testLrmFoo1.' type=kotlin.Int origin=null + CALL 'public final fun print (message: kotlin.Int): kotlin.Unit [inline] declared in kotlin.io' type=kotlin.Unit origin=null + message: GET_VAR 'it: kotlin.Int declared in .testLrmFoo1.' type=kotlin.Int origin=null FUN name:testLrmFoo2 visibility:public modality:FINAL <> (ints:kotlin.collections.List) returnType:kotlin.Unit VALUE_PARAMETER name:ints index:0 type:kotlin.collections.List BLOCK_BODY @@ -78,6 +76,5 @@ FILE fqName: fileName:/nonLocalReturn.kt arg1: CONST Int type=kotlin.Int value=0 then: RETURN type=kotlin.Nothing from='local final fun (it: kotlin.Int): kotlin.Unit declared in .testLrmFoo2' GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit - RETURN type=kotlin.Nothing from='local final fun (it: kotlin.Int): kotlin.Unit declared in .testLrmFoo2' - CALL 'public final fun print (message: kotlin.Int): kotlin.Unit [inline] declared in kotlin.io' type=kotlin.Unit origin=null - message: GET_VAR 'it: kotlin.Int declared in .testLrmFoo2.' type=kotlin.Int origin=null + CALL 'public final fun print (message: kotlin.Int): kotlin.Unit [inline] declared in kotlin.io' type=kotlin.Unit origin=null + message: GET_VAR 'it: kotlin.Int declared in .testLrmFoo2.' type=kotlin.Int origin=null diff --git a/compiler/testData/ir/irText/lambdas/samAdapter.txt b/compiler/testData/ir/irText/lambdas/samAdapter.txt index 3fde9bd39c4..8e9063340a0 100644 --- a/compiler/testData/ir/irText/lambdas/samAdapter.txt +++ b/compiler/testData/ir/irText/lambdas/samAdapter.txt @@ -6,8 +6,7 @@ FILE fqName: fileName:/samAdapter.kt FUN_EXPR type=kotlin.Function0 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .test1' - CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit [inline] declared in kotlin.io' type=kotlin.Unit origin=null - message: CONST String type=kotlin.String value="Hello, world!" + CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit [inline] declared in kotlin.io' type=kotlin.Unit origin=null + message: CONST String type=kotlin.String value="Hello, world!" CALL 'public abstract fun run (): kotlin.Unit declared in java.lang.Runnable' type=kotlin.Unit origin=null $this: GET_VAR 'val hello: java.lang.Runnable [val] declared in .test1' type=java.lang.Runnable origin=null diff --git a/compiler/testData/ir/irText/regressions/integerCoercionToT.txt b/compiler/testData/ir/irText/regressions/integerCoercionToT.txt index f702d14b6ee..d69e58879cd 100644 --- a/compiler/testData/ir/irText/regressions/integerCoercionToT.txt +++ b/compiler/testData/ir/irText/regressions/integerCoercionToT.txt @@ -18,8 +18,7 @@ FILE fqName: fileName:/integerCoercionToT.kt TYPE_PARAMETER name:T index:0 variance: superTypes:[.CPointed] $receiver: VALUE_PARAMETER name: type:.CPointed BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun reinterpret (): T of .reinterpret [inline] declared in ' - CALL 'public final fun TODO (): kotlin.Nothing [inline] declared in kotlin' type=kotlin.Nothing origin=null + CALL 'public final fun TODO (): kotlin.Nothing [inline] declared in kotlin' type=kotlin.Nothing origin=null CLASS CLASS name:CInt32VarX modality:FINAL visibility:public superTypes:[.CPointed] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.CInt32VarX.CInt32VarX> TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] @@ -47,8 +46,7 @@ FILE fqName: fileName:/integerCoercionToT.kt TYPE_PARAMETER name:T_INT index:0 variance: superTypes:[kotlin.Int] $receiver: VALUE_PARAMETER name: type:.CInt32VarX.> BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): T_INT of . declared in ' - CALL 'public final fun TODO (): kotlin.Nothing [inline] declared in kotlin' type=kotlin.Nothing origin=null + CALL 'public final fun TODO (): kotlin.Nothing [inline] declared in kotlin' type=kotlin.Nothing origin=null FUN name: visibility:public modality:FINAL ($receiver:.CInt32VarX.>, value:T_INT of .) returnType:kotlin.Unit correspondingProperty: PROPERTY name:value visibility:public modality:FINAL [var] TYPE_PARAMETER name:T_INT index:0 variance: superTypes:[kotlin.Int] diff --git a/compiler/testData/ir/irText/regressions/newInference/fixationOrder1.txt b/compiler/testData/ir/irText/regressions/newInference/fixationOrder1.txt index b19b33cf4eb..613ce3ddd8d 100644 --- a/compiler/testData/ir/irText/regressions/newInference/fixationOrder1.txt +++ b/compiler/testData/ir/irText/regressions/newInference/fixationOrder1.txt @@ -3,8 +3,7 @@ FILE fqName: fileName:/fixationOrder1.kt TYPE_PARAMETER name:X index:0 variance: superTypes:[kotlin.Any?] TYPE_PARAMETER name:Y index:1 variance: superTypes:[kotlin.Any?] BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun foo (): kotlin.Function1.foo, Y of .foo> declared in ' - CALL 'public final fun TODO (): kotlin.Nothing [inline] declared in kotlin' type=kotlin.Nothing origin=null + CALL 'public final fun TODO (): kotlin.Nothing [inline] declared in kotlin' type=kotlin.Nothing origin=null CLASS INTERFACE name:Inv2 modality:ABSTRACT visibility:public superTypes:[kotlin.Any] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Inv2.Inv2, B of .Inv2> TYPE_PARAMETER name:A index:0 variance: superTypes:[kotlin.Any?] @@ -29,8 +28,7 @@ FILE fqName: fileName:/fixationOrder1.kt VALUE_PARAMETER name:y index:1 type:R of .check VALUE_PARAMETER name:f index:2 type:kotlin.Function1.check, R of .check> BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun check (x: T of .check, y: R of .check, f: kotlin.Function1.check, R of .check>): .Inv2.check, R of .check> declared in ' - CALL 'public final fun TODO (): kotlin.Nothing [inline] declared in kotlin' type=kotlin.Nothing origin=null + CALL 'public final fun TODO (): kotlin.Nothing [inline] declared in kotlin' type=kotlin.Nothing origin=null FUN name:test visibility:public modality:FINAL <> () returnType:.Inv2 BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test (): .Inv2 declared in ' diff --git a/compiler/testData/ir/irText/stubs/builtinMap.txt b/compiler/testData/ir/irText/stubs/builtinMap.txt index 0ea8c8bf634..274309f784b 100644 --- a/compiler/testData/ir/irText/stubs/builtinMap.txt +++ b/compiler/testData/ir/irText/stubs/builtinMap.txt @@ -26,11 +26,10 @@ FILE fqName: fileName:/builtinMap.kt FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:java.util.LinkedHashMap.plus?, V1 of .plus?>{ kotlin.collections.LinkedHashMap.plus?, V1 of .plus?> }) returnType:kotlin.Unit $receiver: VALUE_PARAMETER name: type:java.util.LinkedHashMap.plus?, V1 of .plus?>{ kotlin.collections.LinkedHashMap.plus?, V1 of .plus?> } BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .plus' - TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit - CALL 'public open fun put (key: K of java.util.LinkedHashMap, value: V of java.util.LinkedHashMap): V of java.util.LinkedHashMap? declared in java.util.LinkedHashMap' type=V1 of .plus? origin=null - $this: GET_VAR ': java.util.LinkedHashMap.plus?, V1 of .plus?>{ kotlin.collections.LinkedHashMap.plus?, V1 of .plus?> } declared in .plus.' type=java.util.LinkedHashMap.plus?, V1 of .plus?>{ kotlin.collections.LinkedHashMap.plus?, V1 of .plus?> } origin=null - key: CALL 'public final fun (): A of kotlin.Pair declared in kotlin.Pair' type=K1 of .plus origin=GET_PROPERTY - $this: GET_VAR 'pair: kotlin.Pair.plus, V1 of .plus> declared in .plus' type=kotlin.Pair.plus, V1 of .plus> origin=null - value: CALL 'public final fun (): B of kotlin.Pair declared in kotlin.Pair' type=V1 of .plus origin=GET_PROPERTY - $this: GET_VAR 'pair: kotlin.Pair.plus, V1 of .plus> declared in .plus' type=kotlin.Pair.plus, V1 of .plus> origin=null + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public open fun put (key: K of java.util.LinkedHashMap, value: V of java.util.LinkedHashMap): V of java.util.LinkedHashMap? declared in java.util.LinkedHashMap' type=V1 of .plus? origin=null + $this: GET_VAR ': java.util.LinkedHashMap.plus?, V1 of .plus?>{ kotlin.collections.LinkedHashMap.plus?, V1 of .plus?> } declared in .plus.' type=java.util.LinkedHashMap.plus?, V1 of .plus?>{ kotlin.collections.LinkedHashMap.plus?, V1 of .plus?> } origin=null + key: CALL 'public final fun (): A of kotlin.Pair declared in kotlin.Pair' type=K1 of .plus origin=GET_PROPERTY + $this: GET_VAR 'pair: kotlin.Pair.plus, V1 of .plus> declared in .plus' type=kotlin.Pair.plus, V1 of .plus> origin=null + value: CALL 'public final fun (): B of kotlin.Pair declared in kotlin.Pair' type=V1 of .plus origin=GET_PROPERTY + $this: GET_VAR 'pair: kotlin.Pair.plus, V1 of .plus> declared in .plus' type=kotlin.Pair.plus, V1 of .plus> origin=null diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index d8dd9c90595..bb6be31b0ae 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -1286,6 +1286,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/expressions/whenReturn.kt"); } + @TestMetadata("whenReturnUnit.kt") + public void testWhenReturnUnit() throws Exception { + runTest("compiler/testData/ir/irText/expressions/whenReturnUnit.kt"); + } + @TestMetadata("whenUnusedExpression.kt") public void testWhenUnusedExpression() throws Exception { runTest("compiler/testData/ir/irText/expressions/whenUnusedExpression.kt");