Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguous link for properties from a primary constructor #3179

Open
vmishenev opened this issue Sep 18, 2023 · 4 comments
Open

Ambiguous link for properties from a primary constructor #3179

vmishenev opened this issue Sep 18, 2023 · 4 comments
Labels
kdoc-spec An issue that requires clarification from the KDoc spec's perspective topic: K2 Issues / PRs that are related to the K2 migration. See #2888

Comments

@vmishenev
Copy link
Contributor

vmishenev commented Sep 18, 2023

This example is from the Dokka unit test documented seealso with reference to property for class:

/**
* @see abc Comment to abc
*/
class Foo(val abc: String)

Here abc is a parameter and property.
From the point of IDE view, the link [abc] leads to the same position in a source file independently of whether the abc is a parameter or property.
From the point of generated documentation view, the link [abc] can lead to a parameter (currently, a constructor page) or a property page.
In K1 @see abc always refers to the property Foo.abc.
In K2 - to the parameter abc of constructor.


Proposal
In KDoc there is the same way to assign documentation for a parameter and property from a constructor - only via block tags. So both links are possible.

/**
* @param abc parameter doc
* @property abc property doc
* @constructor some KDoc
*/
class Foo(val abc: String)

To keep a link to the parameter, [abc] should lead to a parameter but [Foo.abc] should lead to a property.

@vmishenev vmishenev added the kdoc-spec An issue that requires clarification from the KDoc spec's perspective label Sep 18, 2023
@IgnatBeresnev IgnatBeresnev changed the title Anambigious link for properties from a primary constructor in @see Anambigious link for properties from a primary constructor Nov 13, 2023
@IgnatBeresnev
Copy link
Member

IgnatBeresnev commented Nov 13, 2023

Also relevant for plain symbol links, such as

/**
 * Enum class with param [x]
 */
enum class EnumKotlinParam(val x: String) {
    NORTH("n"),
    EAST("e")
}

Related: #3334

@atyrin
Copy link
Contributor

atyrin commented Nov 20, 2023

JIC: A usage in the wild (if someone had doubts): https://github.com/square/okhttp/blob/0343ff823c17357c8e1994b4c0f0ea783dcace7a/mockwebserver/src/main/kotlin/mockwebserver3/SocketPolicy.kt#L83
In this case (nested class), with K2, we generate an incorrect link to the property.
http://localhost:63342/okhttp-parent/k2/mockwebserver3/mockwebserver3/-socket-policy/-do-not-read-request-body/--root--.html instead of http://localhost:63342/okhttp-parent/k2/mockwebserver3/mockwebserver3/-socket-policy/-do-not-read-request-body/http2-error-code.html

@vmishenev vmishenev changed the title Anambigious link for properties from a primary constructor Ambigious link for properties from a primary constructor Jan 16, 2024
@vmishenev vmishenev changed the title Ambigious link for properties from a primary constructor Ambiguous link for properties from a primary constructor Jan 16, 2024
@vmishenev vmishenev added the topic: K2 Issues / PRs that are related to the K2 migration. See #2888 label May 15, 2024
@atyrin
Copy link
Contributor

atyrin commented Jul 8, 2024

One more point. It affects also references in the class body:

class ClassWithLongSeeAlsoList(val propInPrimaryConstructor: String) {
    val propInBody: String = ""

   
    /**
     * Adds a [propInPrimaryConstructor] to this group. [propInPrimaryConstructor] is a property from constructor
     *
     * Adds a [propInBody] to this group. [propInBody] is a property in the class body
     */
    fun ref() {
    }
}
image

@vmishenev
Copy link
Contributor Author

This issues was addressed in Kotlin/KEEP#389

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kdoc-spec An issue that requires clarification from the KDoc spec's perspective topic: K2 Issues / PRs that are related to the K2 migration. See #2888
Projects
None yet
Development

No branches or pull requests

3 participants