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:
@@ -115,7 +115,6 @@ val jvmPhases = namedIrFilePhase<JvmBackendContext>(
|
|||||||
annotationPhase then
|
annotationPhase then
|
||||||
tailrecPhase then
|
tailrecPhase then
|
||||||
|
|
||||||
jvmDefaultConstructorPhase then
|
|
||||||
jvmInlineClassPhase then
|
jvmInlineClassPhase then
|
||||||
defaultArgumentStubPhase then
|
defaultArgumentStubPhase then
|
||||||
|
|
||||||
@@ -146,6 +145,7 @@ val jvmPhases = namedIrFilePhase<JvmBackendContext>(
|
|||||||
collectionStubMethodLowering then
|
collectionStubMethodLowering then
|
||||||
bridgePhase then
|
bridgePhase then
|
||||||
jvmOverloadsAnnotationPhase then
|
jvmOverloadsAnnotationPhase then
|
||||||
|
jvmDefaultConstructorPhase then
|
||||||
jvmStaticAnnotationPhase then
|
jvmStaticAnnotationPhase then
|
||||||
staticDefaultFunctionPhase then
|
staticDefaultFunctionPhase then
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -20,7 +20,8 @@ import org.jetbrains.kotlin.ir.util.hasDefaultValue
|
|||||||
internal val jvmDefaultConstructorPhase = makeIrFilePhase(
|
internal val jvmDefaultConstructorPhase = makeIrFilePhase(
|
||||||
::JvmDefaultConstructorLowering,
|
::JvmDefaultConstructorLowering,
|
||||||
name = "JvmDefaultConstructor",
|
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
|
// Quoted from https://kotlinlang.org/docs/reference/classes.html
|
||||||
|
|||||||
+12
@@ -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
|
||||||
|
}
|
||||||
+5
@@ -14879,6 +14879,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/jvmOverloads/primaryConstructor.kt");
|
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")
|
@TestMetadata("privateClass.kt")
|
||||||
public void testPrivateClass() throws Exception {
|
public void testPrivateClass() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/jvmOverloads/privateClass.kt");
|
runTest("compiler/testData/codegen/box/jvmOverloads/privateClass.kt");
|
||||||
|
|||||||
+5
@@ -14879,6 +14879,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/jvmOverloads/primaryConstructor.kt");
|
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")
|
@TestMetadata("privateClass.kt")
|
||||||
public void testPrivateClass() throws Exception {
|
public void testPrivateClass() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/jvmOverloads/privateClass.kt");
|
runTest("compiler/testData/codegen/box/jvmOverloads/privateClass.kt");
|
||||||
|
|||||||
+5
@@ -14884,6 +14884,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/jvmOverloads/primaryConstructor.kt");
|
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")
|
@TestMetadata("privateClass.kt")
|
||||||
public void testPrivateClass() throws Exception {
|
public void testPrivateClass() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/jvmOverloads/privateClass.kt");
|
runTest("compiler/testData/codegen/box/jvmOverloads/privateClass.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user