FIR2IR: force return type of loop body block as Unit

This commit is contained in:
Jinseong Jeon
2021-03-18 12:18:14 -07:00
committed by TeamCityServer
parent 7898d167f3
commit 81999117dc
4 changed files with 10 additions and 5 deletions
@@ -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(
@@ -111,7 +111,7 @@ FILE fqName:<root> 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 <root>.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 <root>.test5' type=kotlin.Int origin=null
@@ -50,7 +50,7 @@ FILE fqName:<root> 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 <root>.test' type=kotlin.Int origin=null
SET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Unit origin=EQ
+1 -1
View File
@@ -537,7 +537,7 @@ FILE fqName:<root> 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 <get-index> (): kotlin.Int declared in <root>.ArrayMapImpl.iterator.<no name provided>' type=kotlin.Int origin=GET_PROPERTY
$this: GET_VAR '<this>: <root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> declared in <root>.ArrayMapImpl.iterator.<no name provided>.computeNext' type=<root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> origin=null