@Deprecated replaces with this.name


#1

A bug recently raised against Koin shows the auto-fix introduce the this keyword when used on an object’s function that is statically imported.

Consider the following code:

package com.example.pkg
import com.example.pkg.StandAloneContext.closeKoin

object StandAloneContext {
    @Deprecated(
        "Renamed, use stopKoin() instead.",
        ReplaceWith("stopKoin()", "com.example.pkg.StandAloneContext.stopKoin")
    )
    fun closeKoin() = stopKoin()

    fun stopKoin() {}
}


fun koin() {
    closeKoin()
}

If closeKoin is written as StandAloneContext.closeKoin() then the auto-fix works as expected and replaces with stopKoin() statically imported. But if as above the function is already statically imported the result is this.stopKoin() which doesn’t compile.

I assume I’m not missing something obvious and this is a bug in how the auto-fix works. It doesn’t seem to matter whether the import in the definition points to the function or the object. I’m using Android Studio 3.3 Canary 6 with Kotlin 1.2.61 plugin.


#2

I’ve created an issue for this at https://youtrack.jetbrains.net/issue/KT-26361