diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt index 5cc45b16dfd..724e90b90af 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt @@ -543,6 +543,11 @@ class Fir2IrVisitor( } } + private val IrStatementOrigin.isLoop: Boolean + get() { + return this == IrStatementOrigin.DO_WHILE_LOOP || this == IrStatementOrigin.WHILE_LOOP || this == IrStatementOrigin.FOR_LOOP + } + private fun FirBlock.convertToIrExpressionOrBlock(origin: IrStatementOrigin? = null): IrExpression { if (statements.size == 1) { val firStatement = statements.single() @@ -550,8 +555,8 @@ class Fir2IrVisitor( return convertToIrExpression(firStatement) } } - val type = - (statements.lastOrNull() as? FirExpression)?.typeRef?.toIrType() ?: irBuiltIns.unitType + val type = if (origin?.isLoop == true) irBuiltIns.unitType + else (statements.lastOrNull() as? FirExpression)?.typeRef?.toIrType() ?: irBuiltIns.unitType return convertWithOffsets { startOffset, endOffset -> if (origin == IrStatementOrigin.DO_WHILE_LOOP) { IrCompositeImpl( diff --git a/compiler/testData/ir/irText/expressions/breakContinueInLoopHeader.fir.txt b/compiler/testData/ir/irText/expressions/breakContinueInLoopHeader.fir.txt index b5683d00b43..3159cd0180f 100644 --- a/compiler/testData/ir/irText/expressions/breakContinueInLoopHeader.fir.txt +++ b/compiler/testData/ir/irText/expressions/breakContinueInLoopHeader.fir.txt @@ -111,7 +111,7 @@ FILE fqName: fileName:/breakContinueInLoopHeader.kt CONST Int type=kotlin.Int value=0 BLOCK type=kotlin.Unit origin=null DO_WHILE label=Inner origin=DO_WHILE_LOOP - body: COMPOSITE type=kotlin.Int origin=DO_WHILE_LOOP + body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP SET_VAR 'var j: kotlin.Int [var] declared in .test5' type=kotlin.Unit origin=EQ CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null $this: GET_VAR 'var j: kotlin.Int [var] declared in .test5' type=kotlin.Int origin=null diff --git a/compiler/testData/ir/irText/expressions/whileDoWhile.fir.txt b/compiler/testData/ir/irText/expressions/whileDoWhile.fir.txt index a0ab96a3e3f..58c14713878 100644 --- a/compiler/testData/ir/irText/expressions/whileDoWhile.fir.txt +++ b/compiler/testData/ir/irText/expressions/whileDoWhile.fir.txt @@ -50,7 +50,7 @@ FILE fqName: fileName:/whileDoWhile.kt arg1: CONST Int type=kotlin.Int value=15 BLOCK type=kotlin.Unit origin=null DO_WHILE label=null origin=DO_WHILE_LOOP - body: COMPOSITE type=kotlin.Int origin=DO_WHILE_LOOP + body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP VAR IR_TEMPORARY_VARIABLE name:tmp_3 type:kotlin.Int [val] GET_VAR 'var x: kotlin.Int [var] declared in .test' type=kotlin.Int origin=null SET_VAR 'var x: kotlin.Int [var] declared in .test' type=kotlin.Unit origin=EQ diff --git a/compiler/testData/ir/irText/firProblems/ArrayMap.fir.txt b/compiler/testData/ir/irText/firProblems/ArrayMap.fir.txt index b4700ceb831..9c06b0d45f0 100644 --- a/compiler/testData/ir/irText/firProblems/ArrayMap.fir.txt +++ b/compiler/testData/ir/irText/firProblems/ArrayMap.fir.txt @@ -537,7 +537,7 @@ FILE fqName: fileName:/ArrayMap.kt BLOCK_BODY BLOCK type=kotlin.Unit origin=null DO_WHILE label=null origin=DO_WHILE_LOOP - body: COMPOSITE type=kotlin.Int origin=DO_WHILE_LOOP + body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:kotlin.Int [val] CALL 'private final fun (): kotlin.Int declared in .ArrayMapImpl.iterator.' type=kotlin.Int origin=GET_PROPERTY $this: GET_VAR ': .ArrayMapImpl.iterator..ArrayMapImpl> declared in .ArrayMapImpl.iterator..computeNext' type=.ArrayMapImpl.iterator..ArrayMapImpl> origin=null