So I have an issue with deprecating extension function. I think it is easiest to explain it on example so let’s say we have these two extension functions (it’s a stupid example but it serves just to show where the issue is).
@Deprecated("message", ReplaceWith("save(MyClass(this), foo, bar)"))
ClassFromLib.saveOld(foo: String, bar: String)
ClassFromLib.save(myClass: MyClass, foo: String, bar: String)
Where my class is something like this:
class MyClass(param: BaseClass)
So the usage for those extension methods would be:
class CallerClass(val libClass: ClassFormLib): BaseClass {
fun someFun() {
libClass.saveOld("foo", "bar")
libClass.save(MyClass(this), "foo", "bar")
}
}
And when in Android Studio I try to replace call of saveOld
function I actually get something like this:
libClass.save(MyClass(libClass), "foo", "bar")
And that is a type mismatch because required is BaseClass
but it got ClassFormLib
, what I really wanted was that I literally get this
not instance on which that extension function is called. I understand that this is expected behaviour and it works as it should - this is detected and it presumes that it reffers to instance of class on which it is called, but I just want literally this
to be there. Is that possible in any way?
I have a stupid workaround for that, I wrote deprecation like this:
@Deprecated("message", ReplaceWith("save(MyClass(thi), foo, bar)"))
ClassFromLib.saveOld(foo: String, bar: String)
But that just stupid because than somebody who uses that need to manually add s
.