[ObjCExport] Add nullable dependency parameter failing test
KT-66068
This commit is contained in:
committed by
Space Team
parent
468efc77dd
commit
87e162e052
+8
-1
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.objcexport.extras
|
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.backend.konan.objcexport.ObjCReferenceType
|
||||||
import org.jetbrains.kotlin.tooling.core.MutableExtras
|
import org.jetbrains.kotlin.tooling.core.MutableExtras
|
||||||
import org.jetbrains.kotlin.tooling.core.extrasKeyOf
|
import org.jetbrains.kotlin.tooling.core.extrasKeyOf
|
||||||
@@ -16,7 +18,12 @@ private val requiresForwardDeclarationKey = extrasKeyOf<Boolean>("isForwardDecla
|
|||||||
* - Default value: `false`.
|
* - Default value: `false`.
|
||||||
* - Example: All types used in function and method signature are expected to render forward declarations
|
* - 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.
|
* ⚠️ Marks [this] [ObjCReferenceType] as 'requires forward declaration' and returns the same instance.
|
||||||
|
|||||||
+4
-3
@@ -193,8 +193,9 @@ private class KtObjCExportHeaderGenerator {
|
|||||||
.filterIsInstance<ObjCReferenceType>()
|
.filterIsInstance<ObjCReferenceType>()
|
||||||
.onEach { type ->
|
.onEach { type ->
|
||||||
if (!type.requiresForwardDeclaration) return@onEach
|
if (!type.requiresForwardDeclaration) return@onEach
|
||||||
if (type is ObjCClassType) objCClassForwardDeclarations += type.className
|
val nonNullType = if (type is ObjCNullableReferenceType) type.nonNullType else type
|
||||||
if (type is ObjCProtocolType) objCProtocolForwardDeclarations += type.protocolName
|
if (nonNullType is ObjCClassType) objCClassForwardDeclarations += nonNullType.className
|
||||||
|
if (nonNullType is ObjCProtocolType) objCProtocolForwardDeclarations += nonNullType.protocolName
|
||||||
}
|
}
|
||||||
.mapNotNull { it.originClassId }
|
.mapNotNull { it.originClassId }
|
||||||
.map(QueueElement::Class).toList()
|
.map(QueueElement::Class).toList()
|
||||||
@@ -237,4 +238,4 @@ private class KtObjCExportHeaderGenerator {
|
|||||||
additionalImports = emptyList()
|
additionalImports = emptyList()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+5
@@ -36,6 +36,11 @@ class ObjCExportForwardDeclarationsTest(
|
|||||||
doTest(forwardDeclarationsDir.resolve("propertyReturningClass"))
|
doTest(forwardDeclarationsDir.resolve("propertyReturningClass"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test - nullable type`() {
|
||||||
|
doTest(forwardDeclarationsDir.resolve("nullableType"))
|
||||||
|
}
|
||||||
|
|
||||||
private fun doTest(root: File) {
|
private fun doTest(root: File) {
|
||||||
if (!root.isDirectory) fail("Expected ${root.absolutePath} to be directory")
|
if (!root.isDirectory) fail("Expected ${root.absolutePath} to be directory")
|
||||||
val generatedHeaders = generator.generateHeaders(root)
|
val generatedHeaders = generator.generateHeaders(root)
|
||||||
|
|||||||
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
@class LongIterator, DoubleIterator, IntIterator;
|
||||||
|
|
||||||
|
@protocol Iterator;
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
class Foo {
|
||||||
|
fun foo(iterator: DoubleIterator? = null) = Unit
|
||||||
|
fun foo(): LongIterator? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
var prop: IntIterator? = null
|
||||||
Reference in New Issue
Block a user