JVM_IR: do not generate two nullary constructors

when the primary constructor with @JvmOverloads has default values for
all arguments.
This commit is contained in:
pyos
2019-06-24 11:04:46 +02:00
committed by max-kammerer
parent 40957ad46a
commit 6a21285aed
6 changed files with 30 additions and 2 deletions
@@ -115,7 +115,6 @@ val jvmPhases = namedIrFilePhase<JvmBackendContext>(
annotationPhase then
tailrecPhase then
jvmDefaultConstructorPhase then
jvmInlineClassPhase then
defaultArgumentStubPhase then
@@ -146,6 +145,7 @@ val jvmPhases = namedIrFilePhase<JvmBackendContext>(
collectionStubMethodLowering then
bridgePhase then
jvmOverloadsAnnotationPhase then
jvmDefaultConstructorPhase then
jvmStaticAnnotationPhase then
staticDefaultFunctionPhase then
@@ -20,7 +20,8 @@ import org.jetbrains.kotlin.ir.util.hasDefaultValue
internal val jvmDefaultConstructorPhase = makeIrFilePhase(
::JvmDefaultConstructorLowering,
name = "JvmDefaultConstructor",
description = "Generate default constructors for Java"
description = "Generate default constructors for Java",
prerequisite = setOf(jvmOverloadsAnnotationPhase)
)
// Quoted from https://kotlinlang.org/docs/reference/classes.html
@@ -0,0 +1,12 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
class C @kotlin.jvm.JvmOverloads constructor(s1: String = "O", s2: String = "K") {
public val status: String = s1 + s2
}
fun box(): String {
val c = (C::class.java.getConstructor().newInstance())
return c.status
}
@@ -14879,6 +14879,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/jvmOverloads/primaryConstructor.kt");
}
@TestMetadata("primaryConstructorWithAllDefaults.kt")
public void testPrimaryConstructorWithAllDefaults() throws Exception {
runTest("compiler/testData/codegen/box/jvmOverloads/primaryConstructorWithAllDefaults.kt");
}
@TestMetadata("privateClass.kt")
public void testPrivateClass() throws Exception {
runTest("compiler/testData/codegen/box/jvmOverloads/privateClass.kt");
@@ -14879,6 +14879,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/jvmOverloads/primaryConstructor.kt");
}
@TestMetadata("primaryConstructorWithAllDefaults.kt")
public void testPrimaryConstructorWithAllDefaults() throws Exception {
runTest("compiler/testData/codegen/box/jvmOverloads/primaryConstructorWithAllDefaults.kt");
}
@TestMetadata("privateClass.kt")
public void testPrivateClass() throws Exception {
runTest("compiler/testData/codegen/box/jvmOverloads/privateClass.kt");
@@ -14884,6 +14884,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/jvmOverloads/primaryConstructor.kt");
}
@TestMetadata("primaryConstructorWithAllDefaults.kt")
public void testPrimaryConstructorWithAllDefaults() throws Exception {
runTest("compiler/testData/codegen/box/jvmOverloads/primaryConstructorWithAllDefaults.kt");
}
@TestMetadata("privateClass.kt")
public void testPrivateClass() throws Exception {
runTest("compiler/testData/codegen/box/jvmOverloads/privateClass.kt");