diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/DefaultParameterValueSubstitutor.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/DefaultParameterValueSubstitutor.kt index 8185851399f..f97dc7d39d1 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/DefaultParameterValueSubstitutor.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/DefaultParameterValueSubstitutor.kt @@ -27,6 +27,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 import org.jetbrains.kotlin.resolve.calls.components.hasDefaultValue import org.jetbrains.kotlin.resolve.isInlineClass import org.jetbrains.kotlin.resolve.jvm.AsmTypes @@ -269,6 +270,7 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) { if (classOrObject.isLocal) return false if (classDescriptor.isInlineClass()) return false if (shouldHideConstructorDueToInlineClassTypeValueParameters(constructorDescriptor)) return false + if (DescriptorUtils.isSealedClass(classDescriptor)) return false if (CodegenBinding.canHaveOuter(state.bindingContext, classDescriptor)) return false diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmDefaultConstructorLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmDefaultConstructorLowering.kt index 18b41f8add2..c0216c8bbff 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmDefaultConstructorLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmDefaultConstructorLowering.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.backend.jvm.JvmBackendContext import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.hasMangledParameters import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.DescriptorVisibilities +import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.ir.builders.declarations.addConstructor import org.jetbrains.kotlin.ir.builders.irBlockBody import org.jetbrains.kotlin.ir.builders.irDelegatingConstructorCall @@ -36,7 +37,9 @@ internal val jvmDefaultConstructorPhase = makeIrFilePhase( private class JvmDefaultConstructorLowering(val context: JvmBackendContext) : ClassLoweringPass { override fun lower(irClass: IrClass) { - if (irClass.kind != ClassKind.CLASS || irClass.visibility == DescriptorVisibilities.LOCAL || irClass.isInline || irClass.isInner) + if (irClass.kind != ClassKind.CLASS || irClass.visibility == DescriptorVisibilities.LOCAL || irClass.isInline || irClass.isInner || + irClass.modality == Modality.SEALED + ) return val primaryConstructor = irClass.constructors.firstOrNull { it.isPrimary } ?: return diff --git a/compiler/testData/codegen/bytecodeListing/sealedClassConstructorWithDefaultParams.kt b/compiler/testData/codegen/bytecodeListing/sealedClassConstructorWithDefaultParams.kt new file mode 100644 index 00000000000..3162a07b22c --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/sealedClassConstructorWithDefaultParams.kt @@ -0,0 +1,3 @@ +// !LANGUAGE: +AllowSealedInheritorsInDifferentFilesOfSamePackage + +sealed class Test(val x: Int = 0) \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/sealedClassConstructorWithDefaultParams.txt b/compiler/testData/codegen/bytecodeListing/sealedClassConstructorWithDefaultParams.txt new file mode 100644 index 00000000000..87a02147c1a --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/sealedClassConstructorWithDefaultParams.txt @@ -0,0 +1,8 @@ +@kotlin.Metadata +public abstract class Test { + // source: 'sealedClassConstructorWithDefaultParams.kt' + private final field x: int + public method (p0: int): void + public synthetic method (p0: int, p1: int, p2: kotlin.jvm.internal.DefaultConstructorMarker): void + public final method getX(): int +} diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java index 5ca776950e8..721d9625682 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java @@ -230,6 +230,11 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { runTest("compiler/testData/codegen/bytecodeListing/rawTypeInSignature.kt"); } + @TestMetadata("sealedClassConstructorWithDefaultParams.kt") + public void testSealedClassConstructorWithDefaultParams() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/sealedClassConstructorWithDefaultParams.kt"); + } + @TestMetadata("strictfpFlag.kt") public void testStrictfpFlag() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/strictfpFlag.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java index ba3514d2eaf..6dd28a1b051 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java @@ -230,6 +230,11 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes runTest("compiler/testData/codegen/bytecodeListing/rawTypeInSignature.kt"); } + @TestMetadata("sealedClassConstructorWithDefaultParams.kt") + public void testSealedClassConstructorWithDefaultParams() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/sealedClassConstructorWithDefaultParams.kt"); + } + @TestMetadata("strictfpFlag.kt") public void testStrictfpFlag() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/strictfpFlag.kt");