# language-evolution

Youssef Shoaib [MOD]

03/19/2022, 3:09 PM
Is it possible to allow
in the future to work for more functions? And specifically, because I prototyped this in Kotlin 1.4 I think, can the resolution order for
be fixed to work for member extension functions (I think when I tried to get it to work
only works for plain extension funs)? My use case is changing the behavior of functions like
. Consider the fp-style Show:
Copy code
interface Show<T> {
    fun T.toString(): String

object IntShow: Show<Int> {
    override fun Int.toString() = "$this is an Integer"
// usage
but this can work for overriding any member function to explicitly change its behavior whenever a receiver is in context. I would wager that this isn't surprising to the user of a library because they explicitly opt-in by bringing a receiver in scope. Could this ever be a kotlin feature or am I dreaming too much lol?
👍 1
❤️ 2


03/20/2022, 6:37 PM
won't be a user-accessible annotation neever. It was introduces in language to cover one specific corner case in kotlin/java stdlib parity (to hide
and resolve to kotlin extension insted) The main problem with
is performance: when compiler tries to resolve some function call, it looks for such function in several scopes and stops when it find good function in one of them. Member functions have high priority, and compiler looks here at the first place (and usually it stops here, because users quite frequently call members). But if
exists than compiler need to look in every scope for each call, because there might be some extension with this annotation, which will incredibly decrease resolution time. Resolution is the most performance heavy part and even with current lazy algorithm (stop of first found function) it takes ~60% of all frontend time
🙏 1
BTW currently we have a hack for `@HidesMembers`: don't stop resolution on found function only if function is called
(to cover exact one existing legal usage of