Kotlin / dokka

API documentation engine for Kotlin
https://kotl.in/dokka
Apache License 2.0
3.44k stars 408 forks source link

Extension functions on generic types with an upper bound #3134

Open ilya-g opened 1 year ago

ilya-g commented 1 year ago

Is your feature request related to a problem? Please describe

Suppose we have an interface and an extension function on a generic type constrained in upper bound by this interface

interface AutoCloseable { ... }

fun <T : AutoCloseable> T.use(....) { }

The function is applicable on all receivers that implement AutoCloseable. Despite that, it is not shown in the extensions list of AutoCloseable and its implementers.

Describe the solution you'd like

Include such extension functions on generic receivers into the list of members+extensions of types that conform to the generic receiver type constraints.

Note: if the extension function's generic receiver type is constrained by several types, this function should be shown only for types that satisfy all of the constraints.

Note: the functions on unconstrained generic receivers, such as let, apply, also, still should not be included in this list.

fedochet commented 9 months ago

Note: the functions on unconstrained generic receivers, such as let, apply, also, still should not be included in this list.

This seems like a really opinionated requirement. Could you please elaborate on why you think this is the right way? And what is the logic to decide which extension functions should be resolved and which shouldn't?

I can give some examples:

fun Any?.ext() {} // can be called on anything, should be resolved because there is a specific type

fun <T> T.ext() {} // can be called on anything, should not be resolved?

fun <T : Any?> T.ext() {} // can be called on anything, should be resolved?