Search code examples
android-studiokotlindeprecation-warning

How do I suppress this deprecated warning on a typealias in Kotlin with Android Studio?


Say I have this snippet in a kotlin file:

typealias GoodThing = Bad.Thing
fun thing(): Bad.Thing = GoodThing

@Deprecated("Deprecated")
sealed class Bad {

    @Deprecated("Deprecated")
    object Thing: Bad()
}

In Android Studio Arctic Fox, I get a deprecated warning on GoodThing in this line:

fun thing(): Bad.Thing = GoodThing

Which reads: typealias GoodThing = Bad.Thing' uses 'Thing', which is deprecated

I want to suppress this warning. But I can't seem to figure out how. I have tried this, but it didn't work:

@Suppress("DEPRECATION")
typealias GoodThing = Bad.Thing

@Suppress("DEPRECATION")
fun thing(): Bad.Thing = GoodThing

What can I do to suppress this warning?

NOTE: Please Assume I do not have access to modify sealed class Bad. So setting DeprecationLevel.HIDDEN on object Thing is not possible.

Also I know this snippet looks odd, but I'm not interested in discussing the "why" of this code snippet. I am simply asking if there is a way to suppress the warning in the snippet. And if it is not possible, is that a bug in Android Studio? Or is that expected behavior?


Solution

  • I figured it out shortly after posting this:

    @Suppress("TYPEALIAS_EXPANSION_DEPRECATION")
    fun thing(): Bad.Thing = GoodThing