JVM_IR: Do not unbox Result argument inside SAM adapters
#KT-45259 Fixed
This commit is contained in:
+22
@@ -18628,6 +18628,28 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/inlineClasses/funInterface")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class FunInterface {
|
||||
@Test
|
||||
public void testAllFilesPresentInFunInterface() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/funInterface"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("argumentIC.kt")
|
||||
public void testArgumentIC() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/argumentIC.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("argumentResult.kt")
|
||||
public void testArgumentResult() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/argumentResult.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/inlineClasses/functionNameMangling")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+3
-1
@@ -658,12 +658,14 @@ class ExpressionCodegen(
|
||||
val genericOrAnyOverride = irFunction.overriddenSymbols.any {
|
||||
val overriddenParam = if (index < 0) it.owner.dispatchReceiverParameter!! else it.owner.valueParameters[index]
|
||||
overriddenParam.type.erasedUpperBound.fqNameWhenAvailable != StandardNames.RESULT_FQ_NAME
|
||||
} || irFunction.parentAsClass.origin == JvmLoweredDeclarationOrigin.LAMBDA_IMPL
|
||||
} || irFunction.parentAsClass.let { it.origin == JvmLoweredDeclarationOrigin.LAMBDA_IMPL && !it.isSamAdapter() }
|
||||
if (!genericOrAnyOverride) return
|
||||
|
||||
StackValue.unboxInlineClass(OBJECT_TYPE, arg.type.erasedUpperBound.defaultType.toIrBasedKotlinType(), mv)
|
||||
}
|
||||
|
||||
private fun IrClass.isSamAdapter(): Boolean = this.superTypes.any { it.getClass()?.isFun == true }
|
||||
|
||||
private fun onlyResultInlineClassParameters(): Boolean = irFunction.valueParameters.all {
|
||||
!it.type.erasedUpperBound.isInline || it.type.erasedUpperBound.fqNameWhenAvailable == StandardNames.RESULT_FQ_NAME
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// WITH_RUNTIME
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
|
||||
inline class Result<T>(val isSuccess: Boolean)
|
||||
|
||||
fun interface ResultHandler<T> {
|
||||
fun onResult(result: Result<T>)
|
||||
}
|
||||
|
||||
fun doSmth(resultHandler: ResultHandler<Boolean>) {
|
||||
resultHandler.onResult(Result(true))
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var res = "FAIL"
|
||||
doSmth { result ->
|
||||
res = if (result.isSuccess) "OK" else "FAIL 1"
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_RUNTIME
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
// IGNORE_BACKEND: JVM
|
||||
|
||||
fun interface ResultHandler<T> {
|
||||
fun onResult(result: Result<T>)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
+22
@@ -18628,6 +18628,28 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/inlineClasses/funInterface")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class FunInterface {
|
||||
@Test
|
||||
public void testAllFilesPresentInFunInterface() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/funInterface"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("argumentIC.kt")
|
||||
public void testArgumentIC() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/argumentIC.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("argumentResult.kt")
|
||||
public void testArgumentResult() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/argumentResult.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/inlineClasses/functionNameMangling")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+22
@@ -18628,6 +18628,28 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/inlineClasses/funInterface")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class FunInterface {
|
||||
@Test
|
||||
public void testAllFilesPresentInFunInterface() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/funInterface"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("argumentIC.kt")
|
||||
public void testArgumentIC() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/argumentIC.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("argumentResult.kt")
|
||||
public void testArgumentResult() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/funInterface/argumentResult.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/inlineClasses/functionNameMangling")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+23
@@ -15504,6 +15504,29 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/inlineClasses/funInterface")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class FunInterface extends AbstractLightAnalysisModeTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInFunInterface() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/funInterface"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("argumentIC.kt")
|
||||
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")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+23
@@ -13657,6 +13657,29 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/inlineClasses/funInterface")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class FunInterface extends AbstractIrJsCodegenBoxES6Test {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR_ES6, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInFunInterface() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/funInterface"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
|
||||
}
|
||||
|
||||
@TestMetadata("argumentIC.kt")
|
||||
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")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Generated
+23
@@ -13114,6 +13114,29 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/inlineClasses/funInterface")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class FunInterface extends AbstractIrJsCodegenBoxTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInFunInterface() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/funInterface"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("argumentIC.kt")
|
||||
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")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Generated
+23
@@ -13179,6 +13179,29 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/inlineClasses/funInterface")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class FunInterface extends AbstractJsCodegenBoxTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInFunInterface() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/funInterface"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@TestMetadata("argumentIC.kt")
|
||||
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")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+23
@@ -7365,6 +7365,29 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/inlineClasses/funInterface")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class FunInterface extends AbstractIrCodegenBoxWasmTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInFunInterface() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/funInterface"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("argumentIC.kt")
|
||||
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")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user