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 c4ee0650513..9358f78f2da 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 @@ -948,13 +948,14 @@ class Fir2IrVisitor( } override fun visitTryExpression(tryExpression: FirTryExpression, data: Any?): IrElement { + // Always generate a block for try, catch and finally blocks. When leaving the finally block in the debugger + // for both Java and Kotlin there is a step on the end brace. For that to happen we need the block with + // that line number for the finally block. return tryExpression.convertWithOffsets { startOffset, endOffset -> IrTryImpl( startOffset, endOffset, tryExpression.typeRef.toIrType(), - tryExpression.tryBlock.convertToIrExpressionOrBlock(), + tryExpression.tryBlock.convertToIrBlock(), tryExpression.catches.map { it.accept(this, data) as IrCatch }, - // Always generate a block for the finally block. When leaving the finally block in the debugger for both - // Java and Kotlin there is a step on the end brace. For that to happen we need the block with that line number. tryExpression.finallyBlock?.convertToIrBlock() ) } @@ -963,7 +964,7 @@ class Fir2IrVisitor( override fun visitCatch(catch: FirCatch, data: Any?): IrElement { return catch.convertWithOffsets { startOffset, endOffset -> val catchParameter = declarationStorage.createIrVariable(catch.parameter, conversionScope.parentFromStack()) - IrCatchImpl(startOffset, endOffset, catchParameter, catch.block.convertToIrExpressionOrBlock()) + IrCatchImpl(startOffset, endOffset, catchParameter, catch.block.convertToIrBlock()) } } diff --git a/compiler/testData/ir/irText/declarations/parameters/useNextParamInLambda.fir.ir.txt b/compiler/testData/ir/irText/declarations/parameters/useNextParamInLambda.fir.ir.txt index 1cc4bc36a2e..23b58fad3f1 100644 --- a/compiler/testData/ir/irText/declarations/parameters/useNextParamInLambda.fir.ir.txt +++ b/compiler/testData/ir/irText/declarations/parameters/useNextParamInLambda.fir.ir.txt @@ -25,7 +25,8 @@ FILE fqName: fileName:/useNextParamInLambda.kt CONST String type=kotlin.String value="fail" TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit TRY type=kotlin.Any - try: CALL 'public final fun f (f1: kotlin.Function0, f2: kotlin.Function0): kotlin.String declared in ' type=kotlin.String origin=null + try: BLOCK type=kotlin.String origin=null + CALL 'public final fun f (f1: kotlin.Function0, f2: kotlin.Function0): kotlin.String declared in ' type=kotlin.String origin=null CATCH parameter=val e: java.lang.Exception [val] declared in .box VAR name:e type:java.lang.Exception [val] BLOCK type=kotlin.Unit origin=null diff --git a/compiler/testData/ir/irText/declarations/parameters/useNextParamInLambda.fir.kt.txt b/compiler/testData/ir/irText/declarations/parameters/useNextParamInLambda.fir.kt.txt index 01a389ca26d..ab535e2e8dc 100644 --- a/compiler/testData/ir/irText/declarations/parameters/useNextParamInLambda.fir.kt.txt +++ b/compiler/testData/ir/irText/declarations/parameters/useNextParamInLambda.fir.kt.txt @@ -10,7 +10,9 @@ fun f(f1: Function0 = local fun (): String { fun box(): String { var result: String = "fail" - try f() + try { // BLOCK + f() + } catch (e: Exception){ // BLOCK result = "OK" } @@ -23,3 +25,4 @@ fun box(): String { } )) } + diff --git a/compiler/testData/ir/irText/expressions/catchParameterAccess.fir.ir.txt b/compiler/testData/ir/irText/expressions/catchParameterAccess.fir.ir.txt index d4e1d810076..a1778c5de59 100644 --- a/compiler/testData/ir/irText/expressions/catchParameterAccess.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/catchParameterAccess.fir.ir.txt @@ -4,9 +4,11 @@ FILE fqName: fileName:/catchParameterAccess.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test (f: kotlin.Function0): kotlin.Unit declared in ' TRY type=kotlin.Unit - try: CALL 'public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0' type=kotlin.Unit origin=INVOKE - $this: GET_VAR 'f: kotlin.Function0 declared in .test' type=kotlin.Function0 origin=VARIABLE_AS_FUNCTION + try: BLOCK type=kotlin.Unit origin=null + CALL 'public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0' type=kotlin.Unit origin=INVOKE + $this: GET_VAR 'f: kotlin.Function0 declared in .test' type=kotlin.Function0 origin=VARIABLE_AS_FUNCTION CATCH parameter=val e: java.lang.Exception [val] declared in .test VAR name:e type:java.lang.Exception [val] - THROW type=kotlin.Nothing - GET_VAR 'val e: java.lang.Exception [val] declared in .test' type=java.lang.Exception origin=null + BLOCK type=kotlin.Nothing origin=null + THROW type=kotlin.Nothing + GET_VAR 'val e: java.lang.Exception [val] declared in .test' type=java.lang.Exception origin=null diff --git a/compiler/testData/ir/irText/expressions/catchParameterAccess.fir.kt.txt b/compiler/testData/ir/irText/expressions/catchParameterAccess.fir.kt.txt index ccb59492ec7..59bba22372c 100644 --- a/compiler/testData/ir/irText/expressions/catchParameterAccess.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/catchParameterAccess.fir.kt.txt @@ -1,5 +1,10 @@ fun test(f: Function0) { - return try f.invoke() - catch (e: Exception)throw e + return try { // BLOCK + f.invoke() + } + catch (e: Exception){ // BLOCK + throw e + } } + diff --git a/compiler/testData/ir/irText/expressions/kt48806.fir.ir.txt b/compiler/testData/ir/irText/expressions/kt48806.fir.ir.txt index 0e1bd224cad..8656c31389c 100644 --- a/compiler/testData/ir/irText/expressions/kt48806.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/kt48806.fir.ir.txt @@ -9,11 +9,13 @@ FILE fqName: fileName:/kt48806.kt FIELD PROPERTY_BACKING_FIELD name:test_1 type:kotlin.Int visibility:private [final] EXPRESSION_BODY TRY type=kotlin.Int - try: THROW type=kotlin.Nothing - CONSTRUCTOR_CALL 'public constructor () declared in java.lang.RuntimeException' type=java.lang.RuntimeException origin=null + try: BLOCK type=kotlin.Nothing origin=null + THROW type=kotlin.Nothing + CONSTRUCTOR_CALL 'public constructor () declared in java.lang.RuntimeException' type=java.lang.RuntimeException origin=null CATCH parameter=val e: java.lang.Exception [val] declared in .A.test_1 VAR name:e type:java.lang.Exception [val] - CONST Int type=kotlin.Int value=1 + BLOCK type=kotlin.Int origin=null + CONST Int type=kotlin.Int value=1 FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.A) returnType:kotlin.Int correspondingProperty: PROPERTY name:test_1 visibility:public modality:FINAL [val] $this: VALUE_PARAMETER name: type:.A @@ -25,11 +27,13 @@ FILE fqName: fileName:/kt48806.kt FIELD PROPERTY_BACKING_FIELD name:test_2 type:kotlin.Int visibility:private [final] EXPRESSION_BODY TRY type=kotlin.Int - try: CONST Int type=kotlin.Int value=1 + try: BLOCK type=kotlin.Int origin=null + CONST Int type=kotlin.Int value=1 CATCH parameter=val e: java.lang.Exception [val] declared in .A.test_2 VAR name:e type:java.lang.Exception [val] - THROW type=kotlin.Nothing - CONSTRUCTOR_CALL 'public constructor () declared in java.lang.RuntimeException' type=java.lang.RuntimeException origin=null + BLOCK type=kotlin.Nothing origin=null + THROW type=kotlin.Nothing + CONSTRUCTOR_CALL 'public constructor () declared in java.lang.RuntimeException' type=java.lang.RuntimeException origin=null FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.A) returnType:kotlin.Int correspondingProperty: PROPERTY name:test_2 visibility:public modality:FINAL [val] $this: VALUE_PARAMETER name: type:.A diff --git a/compiler/testData/ir/irText/expressions/kt48806.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt48806.fir.kt.txt index 0538ba6b047..74f230466fd 100644 --- a/compiler/testData/ir/irText/expressions/kt48806.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/kt48806.fir.kt.txt @@ -6,15 +6,24 @@ class A { } val test_1: Int - field = try throw RuntimeException() - catch (e: Exception)1 + field = try { // BLOCK + throw RuntimeException() + } + catch (e: Exception){ // BLOCK + 1 + } get val test_2: Int - field = try 1 - catch (e: Exception)throw RuntimeException() + field = try { // BLOCK + 1 + } + catch (e: Exception){ // BLOCK + throw RuntimeException() + } get } + diff --git a/compiler/testData/ir/irText/expressions/tryCatch.fir.ir.txt b/compiler/testData/ir/irText/expressions/tryCatch.fir.ir.txt index cc2565f261e..a3940df5ec8 100644 --- a/compiler/testData/ir/irText/expressions/tryCatch.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/tryCatch.fir.ir.txt @@ -2,10 +2,12 @@ FILE fqName: fileName:/tryCatch.kt FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY TRY type=kotlin.Unit - try: CALL 'public final fun println (): kotlin.Unit [inline] declared in kotlin.io.ConsoleKt' type=kotlin.Unit origin=null + try: BLOCK type=kotlin.Unit origin=null + CALL 'public final fun println (): kotlin.Unit [inline] declared in kotlin.io.ConsoleKt' type=kotlin.Unit origin=null CATCH parameter=val e: kotlin.Throwable [val] declared in .test1 VAR name:e type:kotlin.Throwable [val] - CALL 'public final fun println (): kotlin.Unit [inline] declared in kotlin.io.ConsoleKt' type=kotlin.Unit origin=null + BLOCK type=kotlin.Unit origin=null + CALL 'public final fun println (): kotlin.Unit [inline] declared in kotlin.io.ConsoleKt' type=kotlin.Unit origin=null finally: BLOCK type=kotlin.Unit origin=null CALL 'public final fun println (): kotlin.Unit [inline] declared in kotlin.io.ConsoleKt' type=kotlin.Unit origin=null FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Int diff --git a/compiler/testData/ir/irText/expressions/tryCatch.fir.kt.txt b/compiler/testData/ir/irText/expressions/tryCatch.fir.kt.txt index 29b57084a5d..236b2363c00 100644 --- a/compiler/testData/ir/irText/expressions/tryCatch.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/tryCatch.fir.kt.txt @@ -1,6 +1,10 @@ fun test1() { - try println() - catch (e: Throwable)println() + try { // BLOCK + println() + } + catch (e: Throwable){ // BLOCK + println() + } finally { // BLOCK println() } diff --git a/compiler/testData/ir/irText/expressions/tryCatchWithImplicitCast.fir.ir.txt b/compiler/testData/ir/irText/expressions/tryCatchWithImplicitCast.fir.ir.txt index 045359c4e2b..fcdb0a0e37f 100644 --- a/compiler/testData/ir/irText/expressions/tryCatchWithImplicitCast.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/tryCatchWithImplicitCast.fir.ir.txt @@ -10,8 +10,10 @@ FILE fqName: fileName:/tryCatchWithImplicitCast.kt GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit VAR name:t type:kotlin.String [val] TRY type=kotlin.String - try: TYPE_OP type=kotlin.String origin=IMPLICIT_CAST typeOperand=kotlin.String - GET_VAR 'a: kotlin.Any declared in .testImplicitCast' type=kotlin.Any origin=null + try: BLOCK type=kotlin.String origin=null + TYPE_OP type=kotlin.String origin=IMPLICIT_CAST typeOperand=kotlin.String + GET_VAR 'a: kotlin.Any declared in .testImplicitCast' type=kotlin.Any origin=null CATCH parameter=val e: kotlin.Throwable [val] declared in .testImplicitCast VAR name:e type:kotlin.Throwable [val] - CONST String type=kotlin.String value="" + BLOCK type=kotlin.String origin=null + CONST String type=kotlin.String value="" diff --git a/compiler/testData/ir/irText/expressions/tryCatchWithImplicitCast.fir.kt.txt b/compiler/testData/ir/irText/expressions/tryCatchWithImplicitCast.fir.kt.txt index c5b32397587..8ec42ee4689 100644 --- a/compiler/testData/ir/irText/expressions/tryCatchWithImplicitCast.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/tryCatchWithImplicitCast.fir.kt.txt @@ -2,7 +2,12 @@ fun testImplicitCast(a: Any) { when { a !is String -> return Unit } - val t: String = try a /*as String */ - catch (e: Throwable)"" + val t: String = try { // BLOCK + a /*as String */ + } + catch (e: Throwable){ // BLOCK + "" + } } +