Don't emit CAST_NEVER_SUCCEEDS when casting to a forward declaration type
^KT-58929
This commit is contained in:
committed by
Space Team
parent
28f90b3ea8
commit
53584cdd49
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.resolve.konan.diagnostics
|
||||
|
||||
import org.jetbrains.kotlin.builtins.PlatformSpecificCastChecker
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.konan.getForwardDeclarationKindOrNull
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
object NativePlatformSpecificCastChecker : PlatformSpecificCastChecker {
|
||||
override fun isCastPossible(fromType: KotlinType, toType: KotlinType): Boolean {
|
||||
return isCastToAForwardDeclaration(toType)
|
||||
}
|
||||
|
||||
/**
|
||||
* Here, we only check that we are casting to a forward declaration to suppress a CAST_NEVER_SUCCEEDS warning. The cast is further
|
||||
* checked in NativeForwardDeclarationRttiChecker.
|
||||
*/
|
||||
private fun isCastToAForwardDeclaration(forwardDeclarationType: KotlinType): Boolean {
|
||||
val forwardDeclarationClassDescriptor = forwardDeclarationType.constructor.declarationDescriptor
|
||||
if (forwardDeclarationClassDescriptor !is ClassDescriptor) return false
|
||||
return forwardDeclarationClassDescriptor.getForwardDeclarationKindOrNull() != null
|
||||
}
|
||||
|
||||
}
|
||||
+2
-1
@@ -30,7 +30,8 @@ object NativePlatformConfigurator : PlatformConfiguratorBase(
|
||||
NativeObjCNameChecker, NativeObjCNameOverridesChecker,
|
||||
NativeObjCRefinementChecker, NativeObjCRefinementAnnotationChecker,
|
||||
NativeObjCRefinementOverridesChecker, NativeHiddenFromObjCInheritanceChecker,
|
||||
)
|
||||
),
|
||||
platformSpecificCastChecker = NativePlatformSpecificCastChecker
|
||||
) {
|
||||
override fun configureModuleComponents(container: StorageComponentContainer) {
|
||||
container.useInstance(NativeInliningRule)
|
||||
|
||||
Reference in New Issue
Block a user