diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt index bd44fe791c3..d0eff149520 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt @@ -1265,7 +1265,9 @@ class ExpressionsConverter( private val LighterASTNode.usedAsExpression: Boolean get() { var parent = getParent() ?: return true - if (parent.elementType == ANNOTATED_EXPRESSION) { + while (parent.elementType == ANNOTATED_EXPRESSION || + parent.elementType == LABELED_EXPRESSION + ) { parent = parent.getParent() ?: return true } val parentTokenType = parent.tokenType diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 76261fc6047..5a6de38b5de 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -2001,7 +2001,9 @@ open class RawFirBuilder( private val KtExpression.usedAsExpression: Boolean get() { var parent = parent - if (parent.elementType == KtNodeTypes.ANNOTATED_EXPRESSION) { + while (parent.elementType == KtNodeTypes.ANNOTATED_EXPRESSION || + parent.elementType == KtNodeTypes.LABELED_EXPRESSION + ) { parent = parent.parent } if (parent is KtBlockExpression) return false diff --git a/compiler/testData/codegen/bytecodeText/statements/labeled.kt b/compiler/testData/codegen/bytecodeText/statements/labeled.kt index e6d2ba1e488..e916024572a 100644 --- a/compiler/testData/codegen/bytecodeText/statements/labeled.kt +++ b/compiler/testData/codegen/bytecodeText/statements/labeled.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR - fun main() { l@ if (2 != 1) "fail 3" diff --git a/compiler/testData/ir/irText/lambdas/nonLocalReturn.fir.ir.txt b/compiler/testData/ir/irText/lambdas/nonLocalReturn.fir.ir.txt deleted file mode 100644 index 765c1c3280d..00000000000 --- a/compiler/testData/ir/irText/lambdas/nonLocalReturn.fir.ir.txt +++ /dev/null @@ -1,81 +0,0 @@ -FILE fqName: fileName:/nonLocalReturn.kt - FUN name:test0 visibility:public modality:FINAL <> () returnType:kotlin.Unit - BLOCK_BODY - CALL 'public final fun run (block: kotlin.Function0): R of kotlin.StandardKt.run [inline] declared in kotlin.StandardKt' type=kotlin.Nothing origin=null - : kotlin.Nothing - block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Nothing - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test0 (): kotlin.Unit declared in ' - GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit - FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit - BLOCK_BODY - CALL 'public final fun run (block: kotlin.Function0): R of kotlin.StandardKt.run [inline] declared in kotlin.StandardKt' type=kotlin.Unit origin=null - : kotlin.Unit - block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit - BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .test1' - GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit - FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Unit - BLOCK_BODY - CALL 'public final fun run (block: kotlin.Function0): R of kotlin.StandardKt.run [inline] declared in kotlin.StandardKt' type=kotlin.Unit origin=null - : kotlin.Unit - block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit - BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .test2' - GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit - FUN name:test3 visibility:public modality:FINAL <> () returnType:kotlin.Unit - BLOCK_BODY - CALL 'public final fun run (block: kotlin.Function0): R of kotlin.StandardKt.run [inline] declared in kotlin.StandardKt' type=kotlin.Unit origin=null - : kotlin.Unit - block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit - BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .test3' - CALL 'public final fun run (block: kotlin.Function0): R of kotlin.StandardKt.run [inline] declared in kotlin.StandardKt' type=kotlin.Nothing origin=null - : kotlin.Nothing - block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Nothing - BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .test3' - GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit - FUN name:testLrmFoo1 visibility:public modality:FINAL <> (ints:kotlin.collections.List) returnType:kotlin.Unit - VALUE_PARAMETER name:ints index:0 type:kotlin.collections.List - BLOCK_BODY - CALL 'public final fun forEach (action: kotlin.Function1): kotlin.Unit [inline] declared in kotlin.collections.CollectionsKt' type=kotlin.Unit origin=null - : kotlin.Int - $receiver: GET_VAR 'ints: kotlin.collections.List declared in .testLrmFoo1' type=kotlin.collections.List origin=null - action: FUN_EXPR type=kotlin.Function1 origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:kotlin.Int) returnType:kotlin.Unit - VALUE_PARAMETER name:it index:0 type:kotlin.Int - BLOCK_BODY - WHEN type=kotlin.Unit origin=IF - BRANCH - if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ - arg0: GET_VAR 'it: kotlin.Int declared in .testLrmFoo1.' type=kotlin.Int origin=null - arg1: CONST Int type=kotlin.Int value=0 - then: RETURN type=kotlin.Nothing from='local final fun (it: kotlin.Int): kotlin.Unit declared in .testLrmFoo1' - GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit - CALL 'public final fun print (message: kotlin.Int): kotlin.Unit [inline] declared in kotlin.io.ConsoleKt' type=kotlin.Unit origin=null - message: GET_VAR 'it: kotlin.Int declared in .testLrmFoo1.' type=kotlin.Int origin=null - FUN name:testLrmFoo2 visibility:public modality:FINAL <> (ints:kotlin.collections.List) returnType:kotlin.Unit - VALUE_PARAMETER name:ints index:0 type:kotlin.collections.List - BLOCK_BODY - CALL 'public final fun forEach (action: kotlin.Function1): kotlin.Unit [inline] declared in kotlin.collections.CollectionsKt' type=kotlin.Unit origin=null - : kotlin.Int - $receiver: GET_VAR 'ints: kotlin.collections.List declared in .testLrmFoo2' type=kotlin.collections.List origin=null - action: FUN_EXPR type=kotlin.Function1 origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:kotlin.Int) returnType:kotlin.Unit - VALUE_PARAMETER name:it index:0 type:kotlin.Int - BLOCK_BODY - WHEN type=kotlin.Unit origin=IF - BRANCH - if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ - arg0: GET_VAR 'it: kotlin.Int declared in .testLrmFoo2.' type=kotlin.Int origin=null - arg1: CONST Int type=kotlin.Int value=0 - then: RETURN type=kotlin.Nothing from='local final fun (it: kotlin.Int): kotlin.Unit declared in .testLrmFoo2' - GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit - CALL 'public final fun print (message: kotlin.Int): kotlin.Unit [inline] declared in kotlin.io.ConsoleKt' type=kotlin.Unit origin=null - message: GET_VAR 'it: kotlin.Int declared in .testLrmFoo2.' type=kotlin.Int origin=null diff --git a/compiler/testData/ir/irText/lambdas/nonLocalReturn.fir.kt.txt b/compiler/testData/ir/irText/lambdas/nonLocalReturn.fir.kt.txt deleted file mode 100644 index 8792fe14792..00000000000 --- a/compiler/testData/ir/irText/lambdas/nonLocalReturn.fir.kt.txt +++ /dev/null @@ -1,50 +0,0 @@ -fun test0() { - run(block = local fun (): Nothing { - return Unit - } -) -} - -fun test1() { - run(block = local fun () { - return Unit - } -) -} - -fun test2() { - run(block = local fun () { - return Unit - } -) -} - -fun test3() { - run(block = local fun () { - return run(block = local fun (): Nothing { - return Unit - } -) - } -) -} - -fun testLrmFoo1(ints: List) { - ints.forEach(action = local fun (it: Int) { - when { - EQEQ(arg0 = it, arg1 = 0) -> return Unit - } - print(message = it) - } -) -} - -fun testLrmFoo2(ints: List) { - ints.forEach(action = local fun (it: Int) { - when { - EQEQ(arg0 = it, arg1 = 0) -> return Unit - } - print(message = it) - } -) -} diff --git a/compiler/testData/ir/irText/lambdas/nonLocalReturn.kt b/compiler/testData/ir/irText/lambdas/nonLocalReturn.kt index eb21cbba95d..05929f5cf5f 100644 --- a/compiler/testData/ir/irText/lambdas/nonLocalReturn.kt +++ b/compiler/testData/ir/irText/lambdas/nonLocalReturn.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // WITH_STDLIB fun test0() {