Kotlin / binary-compatibility-validator

Public API management tool
Apache License 2.0
761 stars 55 forks source link

Internal constructor is listed in api #171

Open kunyavskiy opened 5 months ago

kunyavskiy commented 5 months ago

For

public class TestBCV(
    public val d: Duration = Duration.ZERO
)

dump is

public final class TestBCV {
    public synthetic fun <init> (JILkotlin/jvm/internal/DefaultConstructorMarker;)V
    public synthetic fun <init> (JLkotlin/jvm/internal/DefaultConstructorMarker;)V
    public final fun getD-UwyO8pc ()J
}

If you make constructor internal like

public class TestBCV internal constructor(
    public val d: Duration = Duration.ZERO
)

Only one of the constructors disappears from the dump

public final class TestBCV {
    public synthetic fun <init> (JILkotlin/jvm/internal/DefaultConstructorMarker;)V
    public final fun getD-UwyO8pc ()J
}
qwwdfsad commented 5 months ago

@fzhinkin while you are at it, please take a look at https://github.com/Kotlin/binary-compatibility-validator/issues/73 and at https://youtrack.jetbrains.com/issue/KT-51073.

It seems like they have the same (or very similar) root cause, it may save you some time

fzhinkin commented 5 months ago

@qwwdfsad thanks! Indeed, it seems to be (almost) the same issue: public synthetic fun <init> (JILkotlin/jvm/internal/DefaultConstructorMarker;)V from the example above is indistinguishable from a method that would be generated for constructor(d: Duration, x: Int).