Kotlin: Inline cast

This commit is contained in:
Anders Fugmann
2026-01-26 10:10:36 +01:00
parent 2320d502db
commit ab495fa843
2 changed files with 5 additions and 7 deletions

View File

@@ -2975,10 +2975,11 @@ open class KotlinFileExtractor(
val locId = tw.getLocation(s)
tw.writeStmts_block(blockId, parent, idx, callable)
tw.writeHasLocation(blockId, locId)
// For Kotlin < 2.3, s.delegate is not-nullable. Cast to be nullable,
// as a workaround to silence warnings for kotlin < 2.3 about the elvis
// operator being redundant.
val delegate: IrVariable? = cast(s.delegate)
// For Kotlin < 2.3, s.delegate is not-nullable, but for Kotlin >= 2.3
// it is nullable. Cast to nullable to handle both cases uniformly.
// For Kotlin >= 2.3, the cast is redundant, hence the suppress.
@Suppress("USELESS_CAST")
val delegate: IrVariable? = s.delegate as IrVariable?
val propId = tw.getFreshIdLabel<DbKt_property>()
if (delegate == null) {

View File

@@ -11,6 +11,3 @@ fun IrFunction.isLocalFunction(): Boolean {
val IrClass.isInterfaceLike
get() = kind == ClassKind.INTERFACE || kind == ClassKind.ANNOTATION_CLASS
@Suppress("UNCHECKED_CAST")
fun <T> cast(value: Any?): T = value as T