[K/N][FIR] Do not emit CAST_NEVER_SUCCEEDS when casting to forward declarations

^KT-61841 Fixed
This commit is contained in:
Vladimir Sukharev
2024-01-04 23:21:24 +01:00
committed by Space Team
parent 050d74a22e
commit 35b83a1225
7 changed files with 60 additions and 8 deletions
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.analysis.native.checkers
import org.jetbrains.kotlin.fir.FirPlatformSpecificCastChecker
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.toRegularClassSymbol
object FirNativeCastChecker : FirPlatformSpecificCastChecker() {
override fun shouldSuppressImpossibleCast(session: FirSession, fromType: ConeKotlinType, toType: ConeKotlinType): Boolean {
return isCastToAForwardDeclaration(session, toType)
}
/**
* Here, we only check that we are casting to a forward declaration to suppress a CAST_NEVER_SUCCEEDS warning.
* The cast would be further checked with FirNativeForwardDeclarationTypeOperatorChecker and FirNativeForwardDeclarationGetClassCallChecker.
*/
private fun isCastToAForwardDeclaration(session: FirSession, forwardDeclarationType: ConeKotlinType): Boolean {
return forwardDeclarationType.toRegularClassSymbol(session)?.forwardDeclarationKindOrNull() != null
}
}