[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()
)
}
}
}
@@ -36,6 +36,11 @@ class ObjCExportForwardDeclarationsTest(
doTest(forwardDeclarationsDir.resolve("propertyReturningClass"))
}
@Test
fun `test - nullable type`() {
doTest(forwardDeclarationsDir.resolve("nullableType"))
}
private fun doTest(root: File) {
if (!root.isDirectory) fail("Expected ${root.absolutePath} to be directory")
val generatedHeaders = generator.generateHeaders(root)
@@ -0,0 +1,3 @@
@class LongIterator, DoubleIterator, IntIterator;
@protocol Iterator;
@@ -0,0 +1,6 @@
class Foo {
fun foo(iterator: DoubleIterator? = null) = Unit
fun foo(): LongIterator? = null
}
var prop: IntIterator? = null