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 5d36652269d..52bb921e5c4 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 @@ -873,7 +873,8 @@ class Fir2IrVisitor( loopMap[whileLoop] = this label = whileLoop.label?.name condition = convertToIrExpression(whileLoop.condition) - body = whileLoop.block.convertToIrExpressionOrBlock(origin) + // NB: here we have strange origin logic, made to be compatible with FE 1.0 + body = whileLoop.block.convertToIrExpressionOrBlock(origin.takeIf { it != IrStatementOrigin.WHILE_LOOP }) loopMap.remove(whileLoop) } } diff --git a/compiler/testData/ir/irText/expressions/badBreakContinue.fir.txt b/compiler/testData/ir/irText/expressions/badBreakContinue.fir.txt index 6646171c5e2..4861247b5ec 100644 --- a/compiler/testData/ir/irText/expressions/badBreakContinue.fir.txt +++ b/compiler/testData/ir/irText/expressions/badBreakContinue.fir.txt @@ -7,14 +7,14 @@ FILE fqName: fileName:/badBreakContinue.kt BLOCK_BODY WHILE label=L1 origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=kotlin.Nothing origin=WHILE_LOOP + body: BLOCK type=kotlin.Nothing origin=null ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind label ERROR to a loop)] ' type=kotlin.Nothing ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind label ERROR to a loop)] ' type=kotlin.Nothing FUN name:test3 visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY WHILE label=L1 origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=kotlin.Unit origin=WHILE_LOOP + body: BLOCK type=kotlin.Unit origin=null VAR name:lambda type:kotlin.Function0 [val] FUN_EXPR type=kotlin.Function0 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Nothing @@ -25,7 +25,7 @@ FILE fqName: fileName:/badBreakContinue.kt BLOCK_BODY WHILE label=null origin=WHILE_LOOP condition: ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing - body: BLOCK type=kotlin.Unit origin=WHILE_LOOP + body: BLOCK type=kotlin.Unit origin=null WHILE label=null origin=WHILE_LOOP condition: ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing - body: BLOCK type=kotlin.Unit origin=WHILE_LOOP + body: BLOCK type=kotlin.Unit origin=null diff --git a/compiler/testData/ir/irText/expressions/breakContinue.fir.txt b/compiler/testData/ir/irText/expressions/breakContinue.fir.txt index 52bbb3be4fe..dfd2a27515b 100644 --- a/compiler/testData/ir/irText/expressions/breakContinue.fir.txt +++ b/compiler/testData/ir/irText/expressions/breakContinue.fir.txt @@ -17,19 +17,19 @@ FILE fqName: fileName:/breakContinue.kt BLOCK_BODY WHILE label=OUTER origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=kotlin.Nothing origin=WHILE_LOOP + body: BLOCK type=kotlin.Nothing origin=null WHILE label=INNER origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=kotlin.Nothing origin=WHILE_LOOP + body: BLOCK type=kotlin.Nothing origin=null BREAK label=INNER loop.label=INNER BREAK label=OUTER loop.label=OUTER BREAK label=OUTER loop.label=OUTER WHILE label=OUTER origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=kotlin.Nothing origin=WHILE_LOOP + body: BLOCK type=kotlin.Nothing origin=null WHILE label=INNER origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=kotlin.Nothing origin=WHILE_LOOP + body: BLOCK type=kotlin.Nothing origin=null CONTINUE label=INNER loop.label=INNER CONTINUE label=OUTER loop.label=OUTER CONTINUE label=OUTER loop.label=OUTER @@ -37,14 +37,14 @@ FILE fqName: fileName:/breakContinue.kt BLOCK_BODY WHILE label=L origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=kotlin.Nothing origin=WHILE_LOOP + body: BLOCK type=kotlin.Nothing origin=null WHILE label=L origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true body: BREAK label=L loop.label=L BREAK label=L loop.label=L WHILE label=L origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=kotlin.Nothing origin=WHILE_LOOP + body: BLOCK type=kotlin.Nothing origin=null WHILE label=L origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true body: CONTINUE label=L loop.label=L diff --git a/compiler/testData/ir/irText/expressions/breakContinueInLoopHeader.fir.txt b/compiler/testData/ir/irText/expressions/breakContinueInLoopHeader.fir.txt index 89f3809e6e0..60b54f615b5 100644 --- a/compiler/testData/ir/irText/expressions/breakContinueInLoopHeader.fir.txt +++ b/compiler/testData/ir/irText/expressions/breakContinueInLoopHeader.fir.txt @@ -4,7 +4,7 @@ FILE fqName: fileName:/breakContinueInLoopHeader.kt BLOCK_BODY WHILE label=L origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=kotlin.Unit origin=WHILE_LOOP + body: BLOCK type=kotlin.Unit origin=null WHILE label=L2 origin=WHILE_LOOP condition: BLOCK type=kotlin.Boolean origin=ELVIS VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Boolean? [val] @@ -19,13 +19,13 @@ FILE fqName: fileName:/breakContinueInLoopHeader.kt if: CONST Boolean type=kotlin.Boolean value=true then: TYPE_OP type=kotlin.Boolean origin=IMPLICIT_CAST typeOperand=kotlin.Boolean GET_VAR 'val tmp_0: kotlin.Boolean? [val] declared in .test1' type=kotlin.Boolean? origin=null - body: BLOCK type=kotlin.Unit origin=WHILE_LOOP + body: BLOCK type=kotlin.Unit origin=null FUN name:test2 visibility:public modality:FINAL <> (c:kotlin.Boolean?) returnType:kotlin.Unit VALUE_PARAMETER name:c index:0 type:kotlin.Boolean? BLOCK_BODY WHILE label=L origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=kotlin.Unit origin=WHILE_LOOP + body: BLOCK type=kotlin.Unit origin=null WHILE label=L2 origin=WHILE_LOOP condition: BLOCK type=kotlin.Boolean origin=ELVIS VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:kotlin.Boolean? [val] @@ -40,13 +40,13 @@ FILE fqName: fileName:/breakContinueInLoopHeader.kt if: CONST Boolean type=kotlin.Boolean value=true then: TYPE_OP type=kotlin.Boolean origin=IMPLICIT_CAST typeOperand=kotlin.Boolean GET_VAR 'val tmp_1: kotlin.Boolean? [val] declared in .test2' type=kotlin.Boolean? origin=null - body: BLOCK type=kotlin.Unit origin=WHILE_LOOP + body: BLOCK type=kotlin.Unit origin=null FUN name:test3 visibility:public modality:FINAL <> (ss:kotlin.collections.List?) returnType:kotlin.Unit VALUE_PARAMETER name:ss index:0 type:kotlin.collections.List? BLOCK_BODY WHILE label=L origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=kotlin.Unit origin=WHILE_LOOP + body: BLOCK type=kotlin.Unit origin=null BLOCK type=kotlin.Unit origin=FOR_LOOP VAR FOR_LOOP_ITERATOR name:tmp_2 type:kotlin.collections.Iterator [val] CALL 'public abstract fun iterator (): kotlin.collections.Iterator [operator] declared in kotlin.collections.List' type=kotlin.collections.Iterator origin=FOR_LOOP_ITERATOR @@ -75,7 +75,7 @@ FILE fqName: fileName:/breakContinueInLoopHeader.kt BLOCK_BODY WHILE label=L origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=kotlin.Unit origin=WHILE_LOOP + body: BLOCK type=kotlin.Unit origin=null BLOCK type=kotlin.Unit origin=FOR_LOOP VAR FOR_LOOP_ITERATOR name:tmp_4 type:kotlin.collections.Iterator [val] CALL 'public abstract fun iterator (): kotlin.collections.Iterator [operator] declared in kotlin.collections.List' type=kotlin.collections.Iterator origin=FOR_LOOP_ITERATOR @@ -105,7 +105,7 @@ FILE fqName: fileName:/breakContinueInLoopHeader.kt CONST Int type=kotlin.Int value=0 WHILE label=Outer origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=kotlin.Unit origin=WHILE_LOOP + body: BLOCK type=kotlin.Unit origin=null SET_VAR 'var i: 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 i: 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 acda0e88efe..982bbd9e1ea 100644 --- a/compiler/testData/ir/irText/expressions/whileDoWhile.fir.txt +++ b/compiler/testData/ir/irText/expressions/whileDoWhile.fir.txt @@ -7,7 +7,7 @@ FILE fqName: fileName:/whileDoWhile.kt condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT arg0: GET_VAR 'var x: kotlin.Int [var] declared in .test' type=kotlin.Int origin=null arg1: CONST Int type=kotlin.Int value=0 - body: BLOCK type=kotlin.Unit origin=WHILE_LOOP + body: BLOCK type=kotlin.Unit origin=null WHILE label=null origin=WHILE_LOOP condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT arg0: GET_VAR 'var x: kotlin.Int [var] declared in .test' type=kotlin.Int origin=null @@ -23,7 +23,7 @@ FILE fqName: fileName:/whileDoWhile.kt condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT arg0: GET_VAR 'var x: kotlin.Int [var] declared in .test' type=kotlin.Int origin=null arg1: CONST Int type=kotlin.Int value=10 - body: BLOCK type=kotlin.Int origin=WHILE_LOOP + body: BLOCK type=kotlin.Int origin=null VAR IR_TEMPORARY_VARIABLE name:tmp_1 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 @@ -69,7 +69,7 @@ FILE fqName: fileName:/whileDoWhile.kt WHILE label=null origin=WHILE_LOOP condition: TYPE_OP type=kotlin.Boolean origin=IMPLICIT_CAST typeOperand=kotlin.Boolean GET_VAR 'val a: kotlin.Any? [val] declared in .testSmartcastInCondition' type=kotlin.Any? origin=null - body: BLOCK type=kotlin.Unit origin=WHILE_LOOP + body: BLOCK type=kotlin.Unit origin=null DO_WHILE label=null origin=DO_WHILE_LOOP body: COMPOSITE type=kotlin.Unit origin=DO_WHILE_LOOP condition: TYPE_OP type=kotlin.Boolean origin=IMPLICIT_CAST typeOperand=kotlin.Boolean diff --git a/compiler/testData/ir/irText/regressions/coercionInLoop.fir.txt b/compiler/testData/ir/irText/regressions/coercionInLoop.fir.txt index c1bc6307f3d..fecdbd66787 100644 --- a/compiler/testData/ir/irText/regressions/coercionInLoop.fir.txt +++ b/compiler/testData/ir/irText/regressions/coercionInLoop.fir.txt @@ -12,7 +12,7 @@ FILE fqName: fileName:/coercionInLoop.kt WHILE label=null origin=WHILE_LOOP condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=null $this: GET_VAR 'val x: kotlin.collections.DoubleIterator [val] declared in .box' type=kotlin.collections.DoubleIterator origin=null - body: BLOCK type=kotlin.Int origin=WHILE_LOOP + body: BLOCK type=kotlin.Int origin=null WHEN type=kotlin.Unit origin=IF BRANCH if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ diff --git a/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInForLoop.fir.txt b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInForLoop.fir.txt index a8bcb54b0c8..fafbbb8ac50 100644 --- a/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInForLoop.fir.txt +++ b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInForLoop.fir.txt @@ -42,7 +42,7 @@ FILE fqName: fileName:/enhancedNullabilityInForLoop.kt WHILE label=null origin=WHILE_LOOP condition: CALL 'public abstract fun hasNext (): kotlin.Boolean [operator] declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=null $this: GET_VAR 'val iterator: kotlin.collections.MutableIterator<.P?> [val] declared in .testDesugaredForInList' type=kotlin.collections.MutableIterator<.P?> origin=null - body: BLOCK type=kotlin.Unit origin=WHILE_LOOP + body: BLOCK type=kotlin.Unit origin=null VAR name:x type:.P? [val] CALL 'public abstract fun next (): T of kotlin.collections.MutableIterator [fake_override,operator] declared in kotlin.collections.MutableIterator' type=.P? origin=null $this: GET_VAR 'val iterator: kotlin.collections.MutableIterator<.P?> [val] declared in .testDesugaredForInList' type=kotlin.collections.MutableIterator<.P?> origin=null