WTF since when does the following result in an amb...
# random
r
WTF since when does the following result in an ambiguity?
Copy code
class A<T>{}
fun <E> A<E>.foo(a: E){}
fun <E> A<E>.foo(b: Int){}
fun test(){
    A<Int?>().foo(null)
}
n
T and E are not the same though right? so just because
A<Int?>
the function `foo`'s generic is not known
although it should definitly not match the second function, so i do not know whats up with that
r
it does not resolve
null
to
Int?
for whatever reason
the following compiles:
Copy code
class A<T>{}
fun <E: Any?> A<E>.foo(a: E){}
fun <E: Any> A<E>.foo(b: E){}
fun test2(){
    A<Int?>().foo(null)
}
I'll file an issue as soon as youtrack is not in read only mode
n
i think whats happening is that it means that this will result in a clash in bytecode
Int or Int? are the same there
r
but overload resolution is done at compile time not at runtime
d
Wait, isn't that ambiguous?
Oh, I just understood lol.
r
also, there is no byte code clash (at least should not)
you can write the following in java as well:
Copy code
public class AExtension {
    public static <E> void  foo(E e){}
    public static void  foo(Integer e){}
}
d
Shouldn't that be
int
?
r
true 😄
but does not really matter for the sake of illustration 😉
d
Yeah, it's probably some edge case with "primitives" in the Kotlin compiler.
r
replace
Int
with
String
the problem remains
quite an old bug as it seems
d
4 years, I don't think they're gonna fix it at this point.
r
seems to be fixed in the new type inference system
so yeah... we need to wait until it is released I guess
d
(sigh). Why do I keep being wrong.
r
Shouldn't that be
int
?
That was correct 😉
😄 1