Kotlin / binary-compatibility-validator

Public API management tool
Apache License 2.0
788 stars 57 forks source link

Outer scope's visibility is not considered when dumping `const val`s #252

Open fzhinkin opened 1 month ago

fzhinkin commented 1 month ago

When dumping static final fields generated for const vals declared inside a companion object, BCV ignores the companion's visibility.

Consider the following classes:

class A private constructor() {
    internal companion object { const val x: Int = 0 } 
}

class B private constructor() {
    private companion object { const val y: Int = 0 } 
}

class C private constructor() {
    @PrivateApi // registered as nonPublicMarker
    companion object { const val z: Int = 0 }
}

In the first two cases, properties are effectively private. In the last case, we kindly ask BCV to treat a companion object as private. However, an ABI dump for all three classes will include fields backing corresponding properties:

public final class cases/companions/A {
    public static final field x I
}

public final class cases/companions/B {
    public static final field y I
}

public final class cases/companions/C {
    public static final field z I
}