JVM_IR: Do not unbox Result argument inside java SAM adapters

#KT-45259
This commit is contained in:
Ilmir Usmanov
2021-03-12 22:59:52 +01:00
parent 4099dfc7e0
commit 149064803d
6 changed files with 57 additions and 5 deletions
@@ -18648,6 +18648,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
public void testArgumentResult() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/argumentResult.kt");
}
@Test
@TestMetadata("javaSam.kt")
public void testJavaSam() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/javaSam.kt");
}
}
@Nested
@@ -661,6 +661,9 @@ class ExpressionCodegen(
} || irFunction.parentAsClass.let { it.origin == JvmLoweredDeclarationOrigin.LAMBDA_IMPL && !it.isSamAdapter() }
if (!genericOrAnyOverride) return
// Result parameter of SAM-wrapper to Java SAM is already unboxed in visitGetValue, do not unbox it anymore
if (irFunction.parentAsClass.superTypes.any { it.getClass()?.isFromJava() == true }) return
StackValue.unboxInlineClass(OBJECT_TYPE, arg.type.erasedUpperBound.defaultType.toIrBasedKotlinType(), mv)
}
@@ -0,0 +1,26 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FULL_RUNTIME
// FILE: ResultHandler.java
import kotlin.Result;
@FunctionalInterface
public interface ResultHandler<T> {
void onResult(Result<T> result);
}
// FILE: test.kt
fun doSmth(resultHandler: ResultHandler<Boolean>) {
resultHandler.onResult(Result.success(true))
}
fun box(): String {
var res = "FAIL"
doSmth { result ->
res = if (result.isSuccess) "OK" else "FAIL 1"
}
return res
}
@@ -18648,6 +18648,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
public void testArgumentResult() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/argumentResult.kt");
}
@Test
@TestMetadata("javaSam.kt")
public void testJavaSam() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/javaSam.kt");
}
}
@Nested
@@ -18648,6 +18648,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
public void testArgumentResult() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/argumentResult.kt");
}
@Test
@TestMetadata("javaSam.kt")
public void testJavaSam() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/javaSam.kt");
}
}
@Nested
@@ -15508,6 +15508,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class FunInterface extends AbstractLightAnalysisModeTest {
@TestMetadata("argumentResult.kt")
public void ignoreArgumentResult() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/argumentResult.kt");
}
@TestMetadata("javaSam.kt")
public void ignoreJavaSam() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/javaSam.kt");
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
@@ -15520,11 +15530,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
public void testArgumentIC() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/argumentIC.kt");
}
@TestMetadata("argumentResult.kt")
public void testArgumentResult() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/argumentResult.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses/functionNameMangling")