diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/DefaultParameterValueSubstitutor.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/DefaultParameterValueSubstitutor.kt index 0eb229f90e190..8f1d3c0aea17c 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/DefaultParameterValueSubstitutor.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/DefaultParameterValueSubstitutor.kt @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.psi.KtParameter import org.jetbrains.kotlin.psi.KtPureClassOrObject import org.jetbrains.kotlin.psi.KtPureElement import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils +import org.jetbrains.kotlin.resolve.DescriptorUtils.isInterface import org.jetbrains.kotlin.resolve.calls.components.hasDefaultValue import org.jetbrains.kotlin.resolve.isInlineClass import org.jetbrains.kotlin.resolve.jvm.AsmTypes @@ -134,8 +135,9 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) { remainingParameters.map { DescriptorToSourceUtils.descriptorToDeclaration(it) as? KtParameter } val generateAsFinal = - functionDescriptor.modality == Modality.FINAL || - state.languageVersionSettings.supportsFeature(LanguageFeature.GenerateJvmOverloadsAsFinal) + (functionDescriptor.modality == Modality.FINAL || + state.languageVersionSettings.supportsFeature(LanguageFeature.GenerateJvmOverloadsAsFinal)) && + !isInterface(functionDescriptor.containingDeclaration) val flags = baseMethodFlags or (if (isStatic) Opcodes.ACC_STATIC else 0) or 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 c726ae78c2707..c7faf4b8ab56a 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 @@ -17739,6 +17739,11 @@ public void testKt21246a() throws Exception { runTest("compiler/testData/codegen/box/jvmStatic/kt21246a.kt"); } + @TestMetadata("kt35716.kt") + public void testKt35716() throws Exception { + runTest("compiler/testData/codegen/box/jvmStatic/kt35716.kt"); + } + @TestMetadata("kt9897_static.kt") public void testKt9897_static() throws Exception { runTest("compiler/testData/codegen/box/jvmStatic/kt9897_static.kt"); diff --git a/compiler/testData/codegen/box/jvmStatic/kt35716.kt b/compiler/testData/codegen/box/jvmStatic/kt35716.kt new file mode 100644 index 0000000000000..19fd9bb1a43fa --- /dev/null +++ b/compiler/testData/codegen/box/jvmStatic/kt35716.kt @@ -0,0 +1,29 @@ +// JVM_TARGET: 1.8 +// TARGET_BACKEND: JVM + +// WITH_RUNTIME +// FILE: Test.java + +class Test { + + public static String test1() { + return A.sayHello(); + } +} + +// FILE: simpleCompanionObject.kt + +interface A { + companion object { + @JvmStatic + @JvmOverloads + fun sayHello(greeting: String = "OK"): String { + return greeting + } + } +} +fun box(): String { + if (Test.test1() != "OK") return "fail 1" + + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index d3d3f33372052..3500dd6a1572c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -19139,6 +19139,11 @@ public void testKt21246a() throws Exception { runTest("compiler/testData/codegen/box/jvmStatic/kt21246a.kt"); } + @TestMetadata("kt35716.kt") + public void testKt35716() throws Exception { + runTest("compiler/testData/codegen/box/jvmStatic/kt35716.kt"); + } + @TestMetadata("kt9897_static.kt") public void testKt9897_static() throws Exception { runTest("compiler/testData/codegen/box/jvmStatic/kt9897_static.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 6dcc68948be47..ae490456eb772 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -19139,6 +19139,11 @@ public void testKt21246a() throws Exception { runTest("compiler/testData/codegen/box/jvmStatic/kt21246a.kt"); } + @TestMetadata("kt35716.kt") + public void testKt35716() throws Exception { + runTest("compiler/testData/codegen/box/jvmStatic/kt35716.kt"); + } + @TestMetadata("kt9897_static.kt") public void testKt9897_static() throws Exception { runTest("compiler/testData/codegen/box/jvmStatic/kt9897_static.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index e1ec6f2ec2ed3..ba0ab6c634a3b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -17739,6 +17739,11 @@ public void testKt21246a() throws Exception { runTest("compiler/testData/codegen/box/jvmStatic/kt21246a.kt"); } + @TestMetadata("kt35716.kt") + public void testKt35716() throws Exception { + runTest("compiler/testData/codegen/box/jvmStatic/kt35716.kt"); + } + @TestMetadata("kt9897_static.kt") public void testKt9897_static() throws Exception { runTest("compiler/testData/codegen/box/jvmStatic/kt9897_static.kt");