From 8aacdb471b211f16666df4201a4435fd74a6eb08 Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Tue, 4 Jul 2023 18:20:33 +0200 Subject: [PATCH] [K/N] Fix: Ignore bridge functions in FunctionReferenceLowering ^KT-59858 --- ...FirLightTreeBlackBoxCodegenTestGenerated.java | 6 ++++++ .../FirPsiBlackBoxCodegenTestGenerated.java | 6 ++++++ compiler/testData/codegen/box/sam/kt59858.kt | 16 ++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 ++++++ .../codegen/IrBlackBoxCodegenTestGenerated.java | 6 ++++++ ...lackBoxCodegenWithIrInlinerTestGenerated.java | 6 ++++++ .../codegen/LightAnalysisModeTestGenerated.java | 5 +++++ .../test/fir/FirJsCodegenBoxTestGenerated.java | 6 ++++++ .../js/test/ir/IrJsCodegenBoxTestGenerated.java | 6 ++++++ .../test/ir/IrJsES6CodegenBoxTestGenerated.java | 6 ++++++ .../konan/lower/FunctionReferenceLowering.kt | 5 ++++- .../FirNativeCodegenBoxTestGenerated.java | 6 ++++++ .../FirNativeCodegenBoxTestNoPLGenerated.java | 6 ++++++ .../NativeCodegenBoxTestGenerated.java | 6 ++++++ .../NativeCodegenBoxTestNoPLGenerated.java | 6 ++++++ .../test/FirWasmCodegenBoxTestGenerated.java | 6 ++++++ .../wasm/test/K1WasmCodegenBoxTestGenerated.java | 6 ++++++ 17 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/sam/kt59858.kt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java index 3195b769fe4..8fbc2a09d97 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java @@ -48607,6 +48607,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr runTest("compiler/testData/codegen/box/sam/kt56188.kt"); } + @Test + @TestMetadata("kt59858.kt") + public void testKt59858() throws Exception { + runTest("compiler/testData/codegen/box/sam/kt59858.kt"); + } + @Test @TestMetadata("nonInlinedSamWrapper.kt") public void testNonInlinedSamWrapper() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java index 5b8c837b8d6..0bff1c8ed04 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java @@ -48607,6 +48607,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo runTest("compiler/testData/codegen/box/sam/kt56188.kt"); } + @Test + @TestMetadata("kt59858.kt") + public void testKt59858() throws Exception { + runTest("compiler/testData/codegen/box/sam/kt59858.kt"); + } + @Test @TestMetadata("nonInlinedSamWrapper.kt") public void testNonInlinedSamWrapper() throws Exception { diff --git a/compiler/testData/codegen/box/sam/kt59858.kt b/compiler/testData/codegen/box/sam/kt59858.kt new file mode 100644 index 00000000000..1c77f360a42 --- /dev/null +++ b/compiler/testData/codegen/box/sam/kt59858.kt @@ -0,0 +1,16 @@ +// MODULE: A +// FILE: A.kt +interface Base { + fun f() : Any +} + +fun interface Child : Base { + override fun f() : Int +} + +// MODULE: B(A) +// FILE: B.kt +fun box(): String { + if (Child { 10 }.f() != 10) return "FAIL" + return "OK" +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 8bde1ac87d2..c8ad4788e7b 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -45841,6 +45841,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/sam/kt56188.kt"); } + @Test + @TestMetadata("kt59858.kt") + public void testKt59858() throws Exception { + runTest("compiler/testData/codegen/box/sam/kt59858.kt"); + } + @Test @TestMetadata("nonInlinedSamWrapper.kt") public void testNonInlinedSamWrapper() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index c378bab0f07..4d1a992bf91 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -48607,6 +48607,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/sam/kt56188.kt"); } + @Test + @TestMetadata("kt59858.kt") + public void testKt59858() throws Exception { + runTest("compiler/testData/codegen/box/sam/kt59858.kt"); + } + @Test @TestMetadata("nonInlinedSamWrapper.kt") public void testNonInlinedSamWrapper() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java index 3455dd8277a..6d0bced646d 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java @@ -48607,6 +48607,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack runTest("compiler/testData/codegen/box/sam/kt56188.kt"); } + @Test + @TestMetadata("kt59858.kt") + public void testKt59858() throws Exception { + runTest("compiler/testData/codegen/box/sam/kt59858.kt"); + } + @Test @TestMetadata("nonInlinedSamWrapper.kt") public void testNonInlinedSamWrapper() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index aba59025057..8adb515d3d1 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -38928,6 +38928,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/sam/kt56188.kt"); } + @TestMetadata("kt59858.kt") + public void testKt59858() throws Exception { + runTest("compiler/testData/codegen/box/sam/kt59858.kt"); + } + @TestMetadata("nonInlinedSamWrapper.kt") public void testNonInlinedSamWrapper() throws Exception { runTest("compiler/testData/codegen/box/sam/nonInlinedSamWrapper.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java index 5131772ef4b..71d374ab9ca 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java @@ -33877,6 +33877,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest { runTest("compiler/testData/codegen/box/sam/kt56188.kt"); } + @Test + @TestMetadata("kt59858.kt") + public void testKt59858() throws Exception { + runTest("compiler/testData/codegen/box/sam/kt59858.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/sam/adapters") @TestDataPath("$PROJECT_ROOT") diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index a600594f9e8..a931cdc8c47 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -33877,6 +33877,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/sam/kt56188.kt"); } + @Test + @TestMetadata("kt59858.kt") + public void testKt59858() throws Exception { + runTest("compiler/testData/codegen/box/sam/kt59858.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/sam/adapters") @TestDataPath("$PROJECT_ROOT") diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java index 80c24c940e7..c2036e3a8fd 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java @@ -33877,6 +33877,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes runTest("compiler/testData/codegen/box/sam/kt56188.kt"); } + @Test + @TestMetadata("kt59858.kt") + public void testKt59858() throws Exception { + runTest("compiler/testData/codegen/box/sam/kt59858.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/sam/adapters") @TestDataPath("$PROJECT_ROOT") diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionReferenceLowering.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionReferenceLowering.kt index cb57487a441..eed56a27926 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionReferenceLowering.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionReferenceLowering.kt @@ -343,7 +343,10 @@ internal class FunctionReferenceLowering(val generationState: NativeGenerationSt val remappedSuperType = (samSuperType.classOrNull ?: error("Expected a class but was: ${samSuperType.render()}")) .typeWith(samSuperType.remappedTypeArguments()) superTypes += remappedSuperType - transformedSuperMethod = remappedSuperType.classOrNull!!.functions.single { it.owner.modality == Modality.ABSTRACT }.owner + transformedSuperMethod = remappedSuperType.classOrNull!!.functions.single { + val function = it.owner + function.modality == Modality.ABSTRACT && function.origin !is DECLARATION_ORIGIN_BRIDGE_METHOD + }.owner } else { val numberOfParameters = unboundFunctionParameters.size if (isSuspend) { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java index 9cf391b7d9d..cbda503b21c 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java @@ -37197,6 +37197,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe runTest("compiler/testData/codegen/box/sam/kt56188.kt"); } + @Test + @TestMetadata("kt59858.kt") + public void testKt59858() throws Exception { + runTest("compiler/testData/codegen/box/sam/kt59858.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/sam/adapters") @TestDataPath("$PROJECT_ROOT") diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java index 905b6e6cafb..e890db85d11 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java @@ -38143,6 +38143,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB runTest("compiler/testData/codegen/box/sam/kt56188.kt"); } + @Test + @TestMetadata("kt59858.kt") + public void testKt59858() throws Exception { + runTest("compiler/testData/codegen/box/sam/kt59858.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/sam/adapters") @TestDataPath("$PROJECT_ROOT") diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java index 2571cd8a397..ae8edf9633d 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java @@ -36725,6 +36725,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/sam/kt56188.kt"); } + @Test + @TestMetadata("kt59858.kt") + public void testKt59858() throws Exception { + runTest("compiler/testData/codegen/box/sam/kt59858.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/sam/adapters") @TestDataPath("$PROJECT_ROOT") diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java index 81c4106ecb5..91fc72ea026 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java @@ -37198,6 +37198,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT runTest("compiler/testData/codegen/box/sam/kt56188.kt"); } + @Test + @TestMetadata("kt59858.kt") + public void testKt59858() throws Exception { + runTest("compiler/testData/codegen/box/sam/kt59858.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/sam/adapters") @TestDataPath("$PROJECT_ROOT") diff --git a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/FirWasmCodegenBoxTestGenerated.java b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/FirWasmCodegenBoxTestGenerated.java index 8bdc220d079..1ce0f7355dd 100644 --- a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/FirWasmCodegenBoxTestGenerated.java +++ b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/FirWasmCodegenBoxTestGenerated.java @@ -33547,6 +33547,12 @@ public class FirWasmCodegenBoxTestGenerated extends AbstractFirWasmCodegenBoxTes runTest("compiler/testData/codegen/box/sam/kt56188.kt"); } + @Test + @TestMetadata("kt59858.kt") + public void testKt59858() throws Exception { + runTest("compiler/testData/codegen/box/sam/kt59858.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/sam/adapters") @TestDataPath("$PROJECT_ROOT") diff --git a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/K1WasmCodegenBoxTestGenerated.java b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/K1WasmCodegenBoxTestGenerated.java index 123ea61feb8..755ee9ab476 100644 --- a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/K1WasmCodegenBoxTestGenerated.java +++ b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/K1WasmCodegenBoxTestGenerated.java @@ -33547,6 +33547,12 @@ public class K1WasmCodegenBoxTestGenerated extends AbstractK1WasmCodegenBoxTest runTest("compiler/testData/codegen/box/sam/kt56188.kt"); } + @Test + @TestMetadata("kt59858.kt") + public void testKt59858() throws Exception { + runTest("compiler/testData/codegen/box/sam/kt59858.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/sam/adapters") @TestDataPath("$PROJECT_ROOT")