[FIR2IR] Add Unit coercion for non-last expressions in try/catch blocks
^KT-61088 Fixed
This commit is contained in:
committed by
Space Team
parent
3d66511ca7
commit
88b80e0ed2
@@ -175,6 +175,15 @@ class Fir2IrImplicitCastInserter(
|
|||||||
|
|
||||||
override fun visitTryExpression(tryExpression: FirTryExpression, data: IrElement): IrElement {
|
override fun visitTryExpression(tryExpression: FirTryExpression, data: IrElement): IrElement {
|
||||||
val irTry = data as IrTry
|
val irTry = data as IrTry
|
||||||
|
|
||||||
|
(irTry.tryResult as? IrContainerExpression)?.let {
|
||||||
|
irTry.tryResult = it.insertImplicitCasts()
|
||||||
|
}
|
||||||
|
for (catch in irTry.catches) {
|
||||||
|
(catch.result as? IrContainerExpression)?.let {
|
||||||
|
catch.result = it.insertImplicitCasts()
|
||||||
|
}
|
||||||
|
}
|
||||||
(irTry.finallyExpression as? IrContainerExpression)?.let {
|
(irTry.finallyExpression as? IrContainerExpression)?.let {
|
||||||
irTry.finallyExpression = it.insertImplicitCasts(coerceLastExpressionToUnit = true)
|
irTry.finallyExpression = it.insertImplicitCasts(coerceLastExpressionToUnit = true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,18 @@ import java.lang.invoke.MethodHandles
|
|||||||
import java.lang.invoke.MethodType
|
import java.lang.invoke.MethodType
|
||||||
|
|
||||||
object O {
|
object O {
|
||||||
fun main() {}
|
var counter = 0
|
||||||
|
fun main() {
|
||||||
|
counter += 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
try {
|
try {
|
||||||
val mh = MethodHandles.lookup().findVirtual(O::class.java, "main", MethodType.methodType(Void.TYPE))
|
val mh = MethodHandles.lookup().findVirtual(O::class.java, "main", MethodType.methodType(Void.TYPE))
|
||||||
mh.invokeExact(O)
|
mh.invokeExact(O)
|
||||||
|
mh.invokeExact(O)
|
||||||
} finally {}
|
} finally {}
|
||||||
|
if (O.counter != 2) return "Fail: counter == ${O.counter}"
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
// !LANGUAGE: +PolymorphicSignature
|
// !LANGUAGE: +PolymorphicSignature
|
||||||
// IGNORE_BACKEND_K2: JVM_IR, JS_IR
|
|
||||||
// FIR status: Fail 9
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// FULL_JDK
|
// FULL_JDK
|
||||||
// SKIP_JDK6
|
// SKIP_JDK6
|
||||||
|
|||||||
@@ -18,13 +18,19 @@ FILE fqName:<root> fileName:/tryCatch.kt
|
|||||||
TRY type=kotlin.Int
|
TRY type=kotlin.Int
|
||||||
try: BLOCK type=kotlin.Int origin=null
|
try: BLOCK type=kotlin.Int origin=null
|
||||||
CALL 'public final fun println (): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
CALL 'public final fun println (): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||||
|
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
|
||||||
|
CONST Int type=kotlin.Int value=100
|
||||||
CONST Int type=kotlin.Int value=42
|
CONST Int type=kotlin.Int value=42
|
||||||
CATCH parameter=val e: kotlin.Throwable declared in <root>.test2
|
CATCH parameter=val e: kotlin.Throwable declared in <root>.test2
|
||||||
VAR CATCH_PARAMETER name:e type:kotlin.Throwable [val]
|
VAR CATCH_PARAMETER name:e type:kotlin.Throwable [val]
|
||||||
BLOCK type=kotlin.Int origin=null
|
BLOCK type=kotlin.Int origin=null
|
||||||
CALL 'public final fun println (): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
CALL 'public final fun println (): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||||
|
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
|
||||||
|
CONST Int type=kotlin.Int value=101
|
||||||
CONST Int type=kotlin.Int value=24
|
CONST Int type=kotlin.Int value=24
|
||||||
finally: BLOCK type=kotlin.Unit origin=null
|
finally: BLOCK type=kotlin.Unit origin=null
|
||||||
CALL 'public final fun println (): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
CALL 'public final fun println (): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||||
|
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
|
||||||
|
CONST Int type=kotlin.Int value=102
|
||||||
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
|
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
|
||||||
CONST Int type=kotlin.Int value=555
|
CONST Int type=kotlin.Int value=555
|
||||||
|
|||||||
@@ -17,14 +17,17 @@ fun test1() {
|
|||||||
fun test2(): Int {
|
fun test2(): Int {
|
||||||
return try {
|
return try {
|
||||||
println()
|
println()
|
||||||
|
100
|
||||||
42
|
42
|
||||||
}
|
}
|
||||||
catch (e: Throwable) {
|
catch (e: Throwable) {
|
||||||
println()
|
println()
|
||||||
|
101
|
||||||
24
|
24
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
println()
|
println()
|
||||||
|
102
|
||||||
555
|
555
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,14 +16,17 @@ fun test1() {
|
|||||||
fun test2(): Int {
|
fun test2(): Int {
|
||||||
return try { // BLOCK
|
return try { // BLOCK
|
||||||
println()
|
println()
|
||||||
|
100 /*~> Unit */
|
||||||
42
|
42
|
||||||
}
|
}
|
||||||
catch (e: Throwable){ // BLOCK
|
catch (e: Throwable){ // BLOCK
|
||||||
println()
|
println()
|
||||||
|
101 /*~> Unit */
|
||||||
24
|
24
|
||||||
}
|
}
|
||||||
finally { // BLOCK
|
finally { // BLOCK
|
||||||
println()
|
println()
|
||||||
|
102 /*~> Unit */
|
||||||
555 /*~> Unit */
|
555 /*~> Unit */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user