aren't extension functions a forward compatibility...
# announcements
b
aren't extension functions a forward compatibility hazard? e.g. you add a function to a class and the lib adds the same method with a different behavior later on. Now your code breaks
a
Yes, that could happen
e
Doesn’t your own extension function shadows the original function?
k
No, member functions always have precedence, https://kotlinlang.org/docs/reference/extensions.html#extensions-are-resolved-statically:
If a class has a member function, and an extension function is defined which has the same receiver type, the same name and is applicable to given arguments, the member always wins.
It's strange it isn't a compilation error then, since you'd never be able to call the extension function.
a
I believe there is a flag for it
And it does show a warning in the source (but yea - IMO it should be a compile error)
e
I think at least should be a warning saying the extension function never called.
a
But it might be called depending on the visibility/scope
If you shadow a package-private (Java) function then else where outside of package it might work fine? (not 100% sure on that)
k
Also an extension function on base class that's shadowed by a child's member function.
a
It should be noted this only breaks at the source - compiled code wont break (since it's compiled to a static function with the receiver as the first arg)
k
Which doesn't really help much because how often are dependencies updated without a compile cycle...
a
If it is compiled and the dependency is updated, it still uses the extension function
👌 1