diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 794d1eea080..af989b5d944 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -8535,6 +8535,16 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/defaultArguments/function/innerExtentionFunctionManyArgs.kt"); } + @TestMetadata("kt36188.kt") + public void testKt36188() throws Exception { + runTest("compiler/testData/codegen/box/defaultArguments/function/kt36188.kt"); + } + + @TestMetadata("kt36188_2.kt") + public void testKt36188_2() throws Exception { + runTest("compiler/testData/codegen/box/defaultArguments/function/kt36188_2.kt"); + } + @TestMetadata("kt5232.kt") public void testKt5232() throws Exception { runTest("compiler/testData/codegen/box/defaultArguments/function/kt5232.kt"); diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceLowering.kt index 2466e476986..8f83d2c2b19 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceLowering.kt @@ -96,12 +96,16 @@ internal class InterfaceLowering(val context: JvmBackendContext) : IrElementTran * ``` */ function.origin == IrDeclarationOrigin.FAKE_OVERRIDE -> { - val implementation = function.resolveFakeOverride()!! + // We check to see if this is a default stub function BEFORE finding the implementation because of a front-end bug + // (KT-36188) where there could be multiple implementations. (resolveFakeOverride() only returns the implementation if + // there's only one.) + if (function.name.asString().endsWith("\$default")) { + continue@loop + } + val implementation = function.resolveFakeOverride() ?: error("No single implementation found for: ${function.render()}") when { - Visibilities.isPrivate(implementation.visibility) || - implementation.isMethodOfAny() || - implementation.origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER -> + Visibilities.isPrivate(implementation.visibility) || implementation.isMethodOfAny() -> continue@loop !implementation.hasJvmDefault() -> { val defaultImpl = createDefaultImpl(function) diff --git a/compiler/testData/codegen/box/defaultArguments/function/kt36188.kt b/compiler/testData/codegen/box/defaultArguments/function/kt36188.kt new file mode 100644 index 00000000000..a924e376825 --- /dev/null +++ b/compiler/testData/codegen/box/defaultArguments/function/kt36188.kt @@ -0,0 +1,20 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// IGNORE_BACKEND: JS + +// Test for KT-36188 bug compatibility between non-IR and IR backends + +interface A { + fun foo(a: String = "OK"): String +} + +interface A2 : A + +interface B { + fun foo(a: String = "Fail"): String +} + +class Impl : A2, B { + override fun foo(a: String) = a +} + +fun box(): String = Impl().foo() diff --git a/compiler/testData/codegen/box/defaultArguments/function/kt36188_2.kt b/compiler/testData/codegen/box/defaultArguments/function/kt36188_2.kt new file mode 100644 index 00000000000..01fe4171b37 --- /dev/null +++ b/compiler/testData/codegen/box/defaultArguments/function/kt36188_2.kt @@ -0,0 +1,22 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// IGNORE_BACKEND: JS + +// Test for KT-36188 bug compatibility between non-IR and IR backends + +interface A { + fun foo(a: String = "OK"): String +} + +interface A2 : A + +interface B { + fun foo(a: String = "Fail"): String +} + +interface C : A2, B + +class Impl : C { + override fun foo(a: String) = a +} + +fun box(): String = Impl().foo() diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 3d792a6469f..34aad09a7ac 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -9680,6 +9680,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/defaultArguments/function/innerExtentionFunctionManyArgs.kt"); } + @TestMetadata("kt36188.kt") + public void testKt36188() throws Exception { + runTest("compiler/testData/codegen/box/defaultArguments/function/kt36188.kt"); + } + + @TestMetadata("kt36188_2.kt") + public void testKt36188_2() throws Exception { + runTest("compiler/testData/codegen/box/defaultArguments/function/kt36188_2.kt"); + } + @TestMetadata("kt5232.kt") public void testKt5232() throws Exception { runTest("compiler/testData/codegen/box/defaultArguments/function/kt5232.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 6eaac41ffac..9d4c8b0fb22 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -9680,6 +9680,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/defaultArguments/function/innerExtentionFunctionManyArgs.kt"); } + @TestMetadata("kt36188.kt") + public void testKt36188() throws Exception { + runTest("compiler/testData/codegen/box/defaultArguments/function/kt36188.kt"); + } + + @TestMetadata("kt36188_2.kt") + public void testKt36188_2() throws Exception { + runTest("compiler/testData/codegen/box/defaultArguments/function/kt36188_2.kt"); + } + @TestMetadata("kt5232.kt") public void testKt5232() throws Exception { runTest("compiler/testData/codegen/box/defaultArguments/function/kt5232.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index eea3e0de026..73a461b4ab4 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -8535,6 +8535,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/defaultArguments/function/innerExtentionFunctionManyArgs.kt"); } + @TestMetadata("kt36188.kt") + public void testKt36188() throws Exception { + runTest("compiler/testData/codegen/box/defaultArguments/function/kt36188.kt"); + } + + @TestMetadata("kt36188_2.kt") + public void testKt36188_2() throws Exception { + runTest("compiler/testData/codegen/box/defaultArguments/function/kt36188_2.kt"); + } + @TestMetadata("kt5232.kt") public void testKt5232() throws Exception { runTest("compiler/testData/codegen/box/defaultArguments/function/kt5232.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 41598b6aee7..6470d494edb 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -7245,6 +7245,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/defaultArguments/function/innerExtentionFunctionManyArgs.kt"); } + @TestMetadata("kt36188.kt") + public void testKt36188() throws Exception { + runTest("compiler/testData/codegen/box/defaultArguments/function/kt36188.kt"); + } + + @TestMetadata("kt36188_2.kt") + public void testKt36188_2() throws Exception { + runTest("compiler/testData/codegen/box/defaultArguments/function/kt36188_2.kt"); + } + @TestMetadata("kt5232.kt") public void testKt5232() throws Exception { runTest("compiler/testData/codegen/box/defaultArguments/function/kt5232.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 473a7080b56..17d9a3839b7 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -7245,6 +7245,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/defaultArguments/function/innerExtentionFunctionManyArgs.kt"); } + @TestMetadata("kt36188.kt") + public void testKt36188() throws Exception { + runTest("compiler/testData/codegen/box/defaultArguments/function/kt36188.kt"); + } + + @TestMetadata("kt36188_2.kt") + public void testKt36188_2() throws Exception { + runTest("compiler/testData/codegen/box/defaultArguments/function/kt36188_2.kt"); + } + @TestMetadata("kt5232.kt") public void testKt5232() throws Exception { runTest("compiler/testData/codegen/box/defaultArguments/function/kt5232.kt");