[ObjCExport] Add nullable dependency parameter failing test

KT-66068
This commit is contained in:
eugene.levenetc
2024-02-23 18:17:50 +01:00
committed by Space Team
parent 468efc77dd
commit 87e162e052
5 changed files with 26 additions and 4 deletions
@@ -5,6 +5,8 @@
package org.jetbrains.kotlin.objcexport.extras
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCNonNullReferenceType
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCNullableReferenceType
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCReferenceType
import org.jetbrains.kotlin.tooling.core.MutableExtras
import org.jetbrains.kotlin.tooling.core.extrasKeyOf
@@ -16,7 +18,12 @@ private val requiresForwardDeclarationKey = extrasKeyOf<Boolean>("isForwardDecla
* - Default value: `false`.
* - Example: All types used in function and method signature are expected to render forward declarations
*/
internal val ObjCReferenceType.requiresForwardDeclaration: Boolean get() = extras[requiresForwardDeclarationKey] ?: false
internal val ObjCReferenceType.requiresForwardDeclaration: Boolean
get() =
when (this) {
is ObjCNonNullReferenceType -> extras[requiresForwardDeclarationKey] ?: false
is ObjCNullableReferenceType -> extras[requiresForwardDeclarationKey] ?: nonNullType.requiresForwardDeclaration
}
/**
* ⚠️ Marks [this] [ObjCReferenceType] as 'requires forward declaration' and returns the same instance.
@@ -193,8 +193,9 @@ private class KtObjCExportHeaderGenerator {
.filterIsInstance<ObjCReferenceType>()
.onEach { type ->
if (!type.requiresForwardDeclaration) return@onEach
if (type is ObjCClassType) objCClassForwardDeclarations += type.className
if (type is ObjCProtocolType) objCProtocolForwardDeclarations += type.protocolName
val nonNullType = if (type is ObjCNullableReferenceType) type.nonNullType else type
if (nonNullType is ObjCClassType) objCClassForwardDeclarations += nonNullType.className
if (nonNullType is ObjCProtocolType) objCProtocolForwardDeclarations += nonNullType.protocolName
}
.mapNotNull { it.originClassId }
.map(QueueElement::Class).toList()
@@ -237,4 +238,4 @@ private class KtObjCExportHeaderGenerator {
additionalImports = emptyList()
)
}
}
}