From 80240198d2621ed7bd63d7b0b6a09945c7511e89 Mon Sep 17 00:00:00 2001 From: Sergej Jaskiewicz Date: Fri, 9 Feb 2024 18:30:41 +0100 Subject: [PATCH] [FIR2IR] Coerce to Unit for last statement in Unit-typed IrBlocks ^KT-59781 Fixed --- .../kotlin/fir/backend/Fir2IrImplicitCastInserter.kt | 2 +- .../codegen/box/fir/listAssignmentInWhen.fir.ir.txt | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt index 7fee95f0abf..e6cb69c2a49 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt @@ -209,7 +209,7 @@ class Fir2IrImplicitCastInserter( } if (this is IrContainerExpression) { - insertImplicitCasts() + insertImplicitCasts(coerceLastExpressionToUnit = type.isUnit()) } val expandedValueType = valueType.fullyExpandedType(session) diff --git a/compiler/testData/codegen/box/fir/listAssignmentInWhen.fir.ir.txt b/compiler/testData/codegen/box/fir/listAssignmentInWhen.fir.ir.txt index e97dcac46b3..9ec52728379 100644 --- a/compiler/testData/codegen/box/fir/listAssignmentInWhen.fir.ir.txt +++ b/compiler/testData/codegen/box/fir/listAssignmentInWhen.fir.ir.txt @@ -8,10 +8,11 @@ FILE fqName: fileName:/listAssignmentInWhen.kt BRANCH if: GET_VAR 'condition: kotlin.Boolean declared in .foo' type=kotlin.Boolean origin=null then: BLOCK type=kotlin.Unit origin=null - CALL 'public abstract fun set (index: kotlin.Int, element: E of kotlin.collections.MutableList): E of kotlin.collections.MutableList declared in kotlin.collections.MutableList' type=kotlin.Any? origin=null - $this: GET_VAR 'list: kotlin.collections.MutableList declared in .foo' type=kotlin.collections.MutableList origin=null - index: CONST Int type=kotlin.Int value=0 - element: CONST String type=kotlin.String value="OK" + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public abstract fun set (index: kotlin.Int, element: E of kotlin.collections.MutableList): E of kotlin.collections.MutableList declared in kotlin.collections.MutableList' type=kotlin.Any? origin=null + $this: GET_VAR 'list: kotlin.collections.MutableList declared in .foo' type=kotlin.collections.MutableList origin=null + index: CONST Int type=kotlin.Int value=0 + element: CONST String type=kotlin.String value="OK" BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit