From 9a328ec75b7c02aed58d02445657fc3bc63170f1 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Tue, 21 Feb 2023 16:23:41 +0100 Subject: [PATCH] [FIR2IR] Apply implicit casts to blocks --- .../fir/backend/Fir2IrImplicitCastInserter.kt | 8 +++-- .../ir/irText/firProblems/ArrayMap.fir.ir.txt | 34 ++++++++++--------- .../ir/irText/firProblems/ArrayMap.fir.kt.txt | 4 +-- 3 files changed, 25 insertions(+), 21 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 6fcc521d32b..d9d84dc2204 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 @@ -201,10 +201,12 @@ class Fir2IrImplicitCastInserter( if (this is IrTypeOperatorCall) { return this } + + if (this is IrContainerExpression) { + insertImplicitCasts() + } + return when { - this is IrContainerExpression -> { - insertImplicitCasts() - } expectedType.isUnit -> { coerceToUnitIfNeeded(this, irBuiltIns) } diff --git a/compiler/testData/ir/irText/firProblems/ArrayMap.fir.ir.txt b/compiler/testData/ir/irText/firProblems/ArrayMap.fir.ir.txt index 71395e227ce..2e5167493eb 100644 --- a/compiler/testData/ir/irText/firProblems/ArrayMap.fir.ir.txt +++ b/compiler/testData/ir/irText/firProblems/ArrayMap.fir.ir.txt @@ -463,15 +463,16 @@ FILE fqName: fileName:/ArrayMap.kt $this: GET_VAR ': .ArrayMapImpl.ArrayMapImpl> declared in .ArrayMapImpl.set' type=.ArrayMapImpl.ArrayMapImpl> origin=null index: GET_VAR 'index: kotlin.Int declared in .ArrayMapImpl.set' type=kotlin.Int origin=null arg1: CONST Null type=kotlin.Nothing? value=null - then: BLOCK type=kotlin.Int origin=null - VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Int [val] - CALL 'public open fun (): kotlin.Int declared in .ArrayMapImpl' type=kotlin.Int origin=GET_PROPERTY + then: TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + BLOCK type=kotlin.Int origin=null + VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Int [val] + CALL 'public open fun (): kotlin.Int declared in .ArrayMapImpl' type=kotlin.Int origin=GET_PROPERTY + $this: GET_VAR ': .ArrayMapImpl.ArrayMapImpl> declared in .ArrayMapImpl.set' type=.ArrayMapImpl.ArrayMapImpl> origin=null + CALL 'private open fun (: kotlin.Int): kotlin.Unit declared in .ArrayMapImpl' type=kotlin.Unit origin=EQ $this: GET_VAR ': .ArrayMapImpl.ArrayMapImpl> declared in .ArrayMapImpl.set' type=.ArrayMapImpl.ArrayMapImpl> origin=null - CALL 'private open fun (: kotlin.Int): kotlin.Unit declared in .ArrayMapImpl' type=kotlin.Unit origin=EQ - $this: GET_VAR ': .ArrayMapImpl.ArrayMapImpl> declared in .ArrayMapImpl.set' type=.ArrayMapImpl.ArrayMapImpl> origin=null - : CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null - $this: GET_VAR 'val tmp_0: kotlin.Int [val] declared in .ArrayMapImpl.set' type=kotlin.Int origin=null - GET_VAR 'val tmp_0: kotlin.Int [val] declared in .ArrayMapImpl.set' type=kotlin.Int origin=null + : CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null + $this: GET_VAR 'val tmp_0: kotlin.Int [val] declared in .ArrayMapImpl.set' type=kotlin.Int origin=null + GET_VAR 'val tmp_0: kotlin.Int [val] declared in .ArrayMapImpl.set' type=kotlin.Int origin=null CALL 'public final fun set (index: kotlin.Int, value: T of kotlin.Array): kotlin.Unit [operator] declared in kotlin.Array' type=kotlin.Unit origin=null $this: CALL 'private final fun (): kotlin.Array declared in .ArrayMapImpl' type=kotlin.Array origin=GET_PROPERTY $this: GET_VAR ': .ArrayMapImpl.ArrayMapImpl> declared in .ArrayMapImpl.set' type=.ArrayMapImpl.ArrayMapImpl> origin=null @@ -633,15 +634,16 @@ FILE fqName: fileName:/ArrayMap.kt $this: GET_VAR ': .ArrayMapImpl.ArrayMapImpl> declared in .ArrayMapImpl.remove' type=.ArrayMapImpl.ArrayMapImpl> origin=null index: GET_VAR 'index: kotlin.Int declared in .ArrayMapImpl.remove' type=kotlin.Int origin=null arg1: CONST Null type=kotlin.Nothing? value=null - then: BLOCK type=kotlin.Int origin=null - VAR IR_TEMPORARY_VARIABLE name:tmp_2 type:kotlin.Int [val] - CALL 'public open fun (): kotlin.Int declared in .ArrayMapImpl' type=kotlin.Int origin=GET_PROPERTY + then: TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + BLOCK type=kotlin.Int origin=null + VAR IR_TEMPORARY_VARIABLE name:tmp_2 type:kotlin.Int [val] + CALL 'public open fun (): kotlin.Int declared in .ArrayMapImpl' type=kotlin.Int origin=GET_PROPERTY + $this: GET_VAR ': .ArrayMapImpl.ArrayMapImpl> declared in .ArrayMapImpl.remove' type=.ArrayMapImpl.ArrayMapImpl> origin=null + CALL 'private open fun (: kotlin.Int): kotlin.Unit declared in .ArrayMapImpl' type=kotlin.Unit origin=EQ $this: GET_VAR ': .ArrayMapImpl.ArrayMapImpl> declared in .ArrayMapImpl.remove' type=.ArrayMapImpl.ArrayMapImpl> origin=null - CALL 'private open fun (: kotlin.Int): kotlin.Unit declared in .ArrayMapImpl' type=kotlin.Unit origin=EQ - $this: GET_VAR ': .ArrayMapImpl.ArrayMapImpl> declared in .ArrayMapImpl.remove' type=.ArrayMapImpl.ArrayMapImpl> origin=null - : CALL 'public final fun dec (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null - $this: GET_VAR 'val tmp_2: kotlin.Int [val] declared in .ArrayMapImpl.remove' type=kotlin.Int origin=null - GET_VAR 'val tmp_2: kotlin.Int [val] declared in .ArrayMapImpl.remove' type=kotlin.Int origin=null + : CALL 'public final fun dec (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null + $this: GET_VAR 'val tmp_2: kotlin.Int [val] declared in .ArrayMapImpl.remove' type=kotlin.Int origin=null + GET_VAR 'val tmp_2: kotlin.Int [val] declared in .ArrayMapImpl.remove' type=kotlin.Int origin=null CALL 'public final fun set (index: kotlin.Int, value: T of kotlin.Array): kotlin.Unit [operator] declared in kotlin.Array' type=kotlin.Unit origin=null $this: CALL 'private final fun (): kotlin.Array declared in .ArrayMapImpl' type=kotlin.Array origin=GET_PROPERTY $this: GET_VAR ': .ArrayMapImpl.ArrayMapImpl> declared in .ArrayMapImpl.remove' type=.ArrayMapImpl.ArrayMapImpl> origin=null diff --git a/compiler/testData/ir/irText/firProblems/ArrayMap.fir.kt.txt b/compiler/testData/ir/irText/firProblems/ArrayMap.fir.kt.txt index a9e5974b78e..9dfe8d52f2c 100644 --- a/compiler/testData/ir/irText/firProblems/ArrayMap.fir.kt.txt +++ b/compiler/testData/ir/irText/firProblems/ArrayMap.fir.kt.txt @@ -195,7 +195,7 @@ internal class ArrayMapImpl : ArrayMap { val : Int = .() .( = .inc()) - } + } /*~> Unit */ } .().set(index = index, value = value) } @@ -251,7 +251,7 @@ internal class ArrayMapImpl : ArrayMap { val : Int = .() .( = .dec()) - } + } /*~> Unit */ } .().set(index = index, value = null) }