diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 77c3c4f438b..21abbb3edad 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -318,7 +318,8 @@ class Fir2IrDeclarationStorage( createIrParameter( valueParameter, index, useStubForDefaultValueStub = function !is FirConstructor || containingClass?.name != Name.identifier("Enum"), - typeContext + typeContext, + skipDefaultParameter = isFakeOverride ).apply { this.parent = parent } @@ -854,10 +855,10 @@ class Fir2IrDeclarationStorage( internal fun saveFakeOverrideInClass( irClass: IrClass, - callableDeclaration: FirCallableDeclaration<*>, + originalDeclaration: FirCallableDeclaration<*>, fakeOverride: FirCallableDeclaration<*> ) { - fakeOverridesInClass.getOrPut(irClass, ::mutableMapOf)[callableDeclaration] = fakeOverride + fakeOverridesInClass.getOrPut(irClass, ::mutableMapOf)[originalDeclaration] = fakeOverride } fun getFakeOverrideInClass( @@ -904,7 +905,8 @@ class Fir2IrDeclarationStorage( valueParameter: FirValueParameter, index: Int = UNDEFINED_PARAMETER_INDEX, useStubForDefaultValueStub: Boolean = true, - typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT + typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT, + skipDefaultParameter: Boolean = false, ): IrValueParameter { val origin = IrDeclarationOrigin.DEFINED val type = valueParameter.returnTypeRef.toIrType() @@ -917,7 +919,7 @@ class Fir2IrDeclarationStorage( isCrossinline = valueParameter.isCrossinline, isNoinline = valueParameter.isNoinline, isHidden = false, isAssignable = false ).apply { - if (valueParameter.defaultValue.let { + if (!skipDefaultParameter && valueParameter.defaultValue.let { it != null && (useStubForDefaultValueStub || it !is FirExpressionStub) } ) { diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/lazy/Fir2IrLazySimpleFunction.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/lazy/Fir2IrLazySimpleFunction.kt index cba4f9b9642..f464e8caf81 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/lazy/Fir2IrLazySimpleFunction.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/lazy/Fir2IrLazySimpleFunction.kt @@ -58,7 +58,7 @@ class Fir2IrLazySimpleFunction( declarationStorage.enterScope(this) fir.valueParameters.mapIndexed { index, valueParameter -> declarationStorage.createIrParameter( - valueParameter, index, + valueParameter, index, skipDefaultParameter = isFakeOverride ).apply { this.parent = this@Fir2IrLazySimpleFunction } diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 9cf4c768fe8..d8000dd5812 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -22830,6 +22830,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/jvmOverloads/simpleJavaCall.kt"); } + @Test + @TestMetadata("subClass.kt") + public void testSubClass() throws Exception { + runTest("compiler/testData/codegen/box/jvmOverloads/subClass.kt"); + } + @Test @TestMetadata("typeParameters.kt") public void testTypeParameters() throws Exception { diff --git a/compiler/testData/codegen/box/jvmOverloads/subClass.kt b/compiler/testData/codegen/box/jvmOverloads/subClass.kt new file mode 100644 index 00000000000..c06b3eb61ea --- /dev/null +++ b/compiler/testData/codegen/box/jvmOverloads/subClass.kt @@ -0,0 +1,15 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME + +open class A { + @JvmOverloads + fun foo(x: String, y: String = "", z: String = "K"): String { + return x + y + z + } +} + +class B : A() + +fun box(): String { + return B().foo("O") +} 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 9747a653863..cb2bbd13aa2 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 @@ -22830,6 +22830,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/jvmOverloads/simpleJavaCall.kt"); } + @Test + @TestMetadata("subClass.kt") + public void testSubClass() throws Exception { + runTest("compiler/testData/codegen/box/jvmOverloads/subClass.kt"); + } + @Test @TestMetadata("typeParameters.kt") public void testTypeParameters() 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 23fb86aa543..5dce4b17e56 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 @@ -22830,6 +22830,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/jvmOverloads/simpleJavaCall.kt"); } + @Test + @TestMetadata("subClass.kt") + public void testSubClass() throws Exception { + runTest("compiler/testData/codegen/box/jvmOverloads/subClass.kt"); + } + @Test @TestMetadata("typeParameters.kt") public void testTypeParameters() 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 9be202977b2..43771bfe58f 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -19295,6 +19295,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/jvmOverloads/simpleJavaCall.kt"); } + @TestMetadata("subClass.kt") + public void testSubClass() throws Exception { + runTest("compiler/testData/codegen/box/jvmOverloads/subClass.kt"); + } + @TestMetadata("typeParameters.kt") public void testTypeParameters() throws Exception { runTest("compiler/testData/codegen/box/jvmOverloads/typeParameters.kt");