Kotlin / binary-compatibility-validator

Public API management tool
Apache License 2.0
800 stars 59 forks source link

`public` members of non-API supertype should be visible in the inheritor #217

Open dovchinnikov opened 5 months ago

dovchinnikov commented 5 months ago

Example 1

@PrivateApi
class KtPrivateApi {
  fun foo() = Unit
}

class KtPublicApi : KtPrivateApi() {
}

fun usage() {
  KtPublicApi().foo() // ok, if @PrivateApi applies only for the class declaration but not its members
}

Example 2

This is not applicable for Kotlin, but should be supported in a library, which has compiled classes as input.

class JavaPackagePrivateClass { 
    public void foo() {} 
}
public class JavaPublicClass extends JavaPackagePrivateClass {

}

void usage() {
  new JavaPublicClass().foo(); // accessible 
}

For IJ, I've implemented this here: https://github.com/JetBrains/intellij-community/blob/f8819a2580a0cc6c2f6a456a6a5fa83bf2e3cf7e/tools/apiDump/src/impl.kt#L134

Also please take a look at supertype expansion: https://github.com/JetBrains/intellij-community/blob/f8819a2580a0cc6c2f6a456a6a5fa83bf2e3cf7e/tools/apiDump/src/impl.kt#L340 It solves this problem: https://github.com/Kotlin/binary-compatibility-validator/blob/3a7003363502236e64bbf044540e569b3eb808a4/src/main/kotlin/api/KotlinSignaturesLoading.kt#L276