From ab495fa843311a8e5f106f7420d1c33c3a72f2ff Mon Sep 17 00:00:00 2001 From: Anders Fugmann Date: Mon, 26 Jan 2026 10:10:36 +0100 Subject: [PATCH] Kotlin: Inline cast --- .../src/main/kotlin/KotlinFileExtractor.kt | 9 +++++---- java/kotlin-extractor/src/main/kotlin/utils/Helpers.kt | 3 --- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt b/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt index 70819c455fc..1c2ed959caf 100644 --- a/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt +++ b/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt @@ -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() if (delegate == null) { diff --git a/java/kotlin-extractor/src/main/kotlin/utils/Helpers.kt b/java/kotlin-extractor/src/main/kotlin/utils/Helpers.kt index e3a4af08fbf..aee909b1eb4 100644 --- a/java/kotlin-extractor/src/main/kotlin/utils/Helpers.kt +++ b/java/kotlin-extractor/src/main/kotlin/utils/Helpers.kt @@ -11,6 +11,3 @@ fun IrFunction.isLocalFunction(): Boolean { val IrClass.isInterfaceLike get() = kind == ClassKind.INTERFACE || kind == ClassKind.ANNOTATION_CLASS - -@Suppress("UNCHECKED_CAST") -fun cast(value: Any?): T = value as T