Hi, I find that this code generates 4 classes to r...
# announcements
b
Hi, I find that this code generates 4 classes to represent ‘::x’, is it a bug? Thus making ‘::x === ::x’ equals false.
Copy code
fun main() {
    val a = ::x
    val b = ::x
    val c = ::x
    val d = ::x
}

fun x(){

}
t
Look at the generated code, ::x generate something that calls x it's not the same as x() so each ::x generate that new object that calls x and so ::x do no exist.
s
Why would you want to compare function references? And still, using this reference logic, comparing different references would give you
false
.
b
Two points. 1. it sound weird and counterintuitive. 2. it makes the bytecode larger. Maybe need some optimizations for the reference of the same function?
Is there any reason why generating separated classes for every call of the function reference of the same function?
s
maybe
::
captures also the local scope?!?
there might also be issues with memory leaks. having only one instance would mean that instance would have to be global static while the current way is garbage collectable?!?
d
Perhaps it could be the same class for (binary size) optimization purposes, but there might be valid reasons for it not to be the same instance as others have suggested.
👍 1
a
Please see discussion in https://youtrack.jetbrains.com/issue/KT-15690 and vote/watch issue for updates.