dokka icon indicating copy to clipboard operation
dokka copied to clipboard

[K2] Incorrect modifier for property from getter/setter

Open atyrin opened this issue 1 year ago • 3 comments

The case is pretty synthetic, but I had such code in my project, so Parent.java

public class Parent {
    public int publicPropertyWithProtectedGetterProtectedSetter = 0;

    protected int getPublicPropertyWithProtectedGetterProtectedSetter() {
        return publicPropertyWithProtectedGetterProtectedSetter;
    }

    protected void setPublicPropertyWithProtectedGetterProtectedSetter(int publicPropertyWithProtectedGetterProtectedSetter) {
        this.publicPropertyWithProtectedGetterProtectedSetter = publicPropertyWithProtectedGetterProtectedSetter;
    }
}

Child.kt

open class Child: Parent()

In K1 Child list member is just the same as in the code: image


In K2 getter/setter is omitted. But for some reason protected wins over public image

Installation

  • Dokka version: 1.9.20 Parent: https://github.com/Kotlin/dokka/issues/3328

atyrin avatar Nov 13 '23 16:11 atyrin

The behaviour inside IntelliJ IDEA differs based on context, and differs based on usage (i.e it might not show getters/setters in autocomplete, but it doesn't mean it'll show an error if you invoke it manually). So the IDE is flexible, it has fewer constraints.

Dokka, on the other hand, only has a single static HTML page for such classes, so we need to figure out what to show our users - do we show them getters and setters? Should DokkaConfiguration#visibility play a role here?

We should also ask if K2 changes Java-Kotlin interop in any known and significant way, and if they have any sort of "specification" tests that would make sure the behaviour hasn't changed in a major way.

IgnatBeresnev avatar Dec 08 '23 15:12 IgnatBeresnev

Spike: #3576

Is blocking?

  • Testing: no
  • Beta: yes (not necessarily the fix, but need to figure out how it should work)

IgnatBeresnev avatar Apr 26 '24 12:04 IgnatBeresnev

It is related to https://github.com/Kotlin/dokka/issues/3338#issuecomment-2112381563 Also, we decided to not distinguish the protected keyword between Kotlin and Java since it seems the use case when an Java declaration is externally used within the same package is unpopular.

In Kotlin - visible in subclasses In Java - visible in subclasses and the same package

vmishenev avatar May 15 '24 12:05 vmishenev