[K/N] Handle Unit? and Nothing? correctly in finally transformation
^KT-52985
This commit is contained in:
+6
@@ -17669,6 +17669,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/finally/objectInFinally.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("returnNullFromInlined.kt")
|
||||
public void testReturnNullFromInlined() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/finally/returnNullFromInlined.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("someStuff.kt")
|
||||
public void testSomeStuff() throws Exception {
|
||||
|
||||
+2
-3
@@ -267,9 +267,8 @@ class FinallyBlocksLowering(val context: CommonBackendContext, private val throw
|
||||
value: IrExpression,
|
||||
finallyExpression: IrExpression
|
||||
): IrExpression {
|
||||
val returnTypeClassifier = (type as? IrSimpleType)?.classifier
|
||||
return when (returnTypeClassifier) {
|
||||
context.irBuiltIns.unitClass, context.irBuiltIns.nothingClass -> irBlock(value, null, type) {
|
||||
return when {
|
||||
type.isUnit() || type.isNothing() -> irBlock(value, null, type) {
|
||||
+irReturnableBlock(symbol, type) {
|
||||
+value
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
inline fun <T> withCatch(block: () -> T?) : T? {
|
||||
try {
|
||||
return block()
|
||||
} catch (e: NullPointerException) {
|
||||
return null
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
fun f1() = withCatch<Int> { null }
|
||||
fun f2() = withCatch<Unit> { null }
|
||||
fun f3() = withCatch<Nothing> { null }
|
||||
|
||||
inline fun <T> withOutCatch(block: () -> T?) : T? {
|
||||
try {
|
||||
return block()
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
fun f4() = withOutCatch<Int> { null }
|
||||
fun f5() = withOutCatch<Unit> { null }
|
||||
fun f6() = withOutCatch<Nothing> { null }
|
||||
|
||||
|
||||
fun box() : String {
|
||||
if (f1() != null) return "FAIL1"
|
||||
if (f2() != null) return "FAIL2"
|
||||
if (f3() != null) return "FAIL3"
|
||||
if (f4() != null) return "FAIL4"
|
||||
if (f5() != null) return "FAIL5"
|
||||
if (f6() != null) return "FAIL6"
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -17213,6 +17213,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/finally/objectInFinally.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("returnNullFromInlined.kt")
|
||||
public void testReturnNullFromInlined() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/finally/returnNullFromInlined.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("someStuff.kt")
|
||||
public void testSomeStuff() throws Exception {
|
||||
|
||||
+6
@@ -17669,6 +17669,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/finally/objectInFinally.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("returnNullFromInlined.kt")
|
||||
public void testReturnNullFromInlined() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/finally/returnNullFromInlined.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("someStuff.kt")
|
||||
public void testSomeStuff() throws Exception {
|
||||
|
||||
+5
@@ -14257,6 +14257,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/finally/objectInFinally.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("returnNullFromInlined.kt")
|
||||
public void testReturnNullFromInlined() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/finally/returnNullFromInlined.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("someStuff.kt")
|
||||
public void testSomeStuff() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/finally/someStuff.kt");
|
||||
|
||||
+6
@@ -13339,6 +13339,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/finally/objectInFinally.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("returnNullFromInlined.kt")
|
||||
public void testReturnNullFromInlined() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/finally/returnNullFromInlined.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("someStuff.kt")
|
||||
public void testSomeStuff() throws Exception {
|
||||
|
||||
+6
@@ -13381,6 +13381,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/finally/objectInFinally.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("returnNullFromInlined.kt")
|
||||
public void testReturnNullFromInlined() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/finally/returnNullFromInlined.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("someStuff.kt")
|
||||
public void testSomeStuff() throws Exception {
|
||||
|
||||
+5
@@ -11887,6 +11887,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
runTest("compiler/testData/codegen/box/finally/objectInFinally.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("returnNullFromInlined.kt")
|
||||
public void testReturnNullFromInlined() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/finally/returnNullFromInlined.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("someStuff.kt")
|
||||
public void testSomeStuff() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/finally/someStuff.kt");
|
||||
|
||||
+6
@@ -14413,6 +14413,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
|
||||
runTest("compiler/testData/codegen/box/finally/objectInFinally.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("returnNullFromInlined.kt")
|
||||
public void testReturnNullFromInlined() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/finally/returnNullFromInlined.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("someStuff.kt")
|
||||
public void testSomeStuff() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user