Make Objective-C blocks conform to kotlin.Function<*> interface (#3492)
This commit is contained in:
committed by
GitHub
parent
61702a64c0
commit
1d18008449
+1
-1
@@ -451,7 +451,7 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
|
||||
val superClass = context.ir.symbols.any.owner
|
||||
|
||||
assert(superClass.implementedInterfaces.isEmpty())
|
||||
val interfaces = listOf(irClass.typeInfoPtr)
|
||||
val interfaces = (listOf(irClass) + irClass.implementedInterfaces).map { it.typeInfoPtr }
|
||||
val interfacesPtr = staticData.placeGlobalConstArray("",
|
||||
pointerType(runtime.typeInfoType), interfaces)
|
||||
|
||||
|
||||
@@ -1055,6 +1055,8 @@ __attribute__((swift_name("ValuesKt")))
|
||||
+ (void (^)(void))asNothingBlockBlock:(id _Nullable (^)(void))block __attribute__((swift_name("asNothingBlock(block:)")));
|
||||
+ (void (^ _Nullable)(void))getNullBlock __attribute__((swift_name("getNullBlock()")));
|
||||
+ (BOOL)isBlockNullBlock:(void (^ _Nullable)(void))block __attribute__((swift_name("isBlockNull(block:)")));
|
||||
+ (BOOL)isFunctionObj:(id _Nullable)obj __attribute__((swift_name("isFunction(obj:)")));
|
||||
+ (BOOL)isFunction0Obj:(id _Nullable)obj __attribute__((swift_name("isFunction0(obj:)")));
|
||||
+ (void)takeForwardDeclaredClassObj:(ForwardDeclaredClass *)obj __attribute__((swift_name("takeForwardDeclaredClass(obj:)")));
|
||||
+ (void)takeForwardDeclaredProtocolObj:(id<ForwardDeclared>)obj __attribute__((swift_name("takeForwardDeclaredProtocol(obj:)")));
|
||||
+ (void)error __attribute__((swift_name("error()"))) __attribute__((unavailable("error")));
|
||||
|
||||
@@ -432,6 +432,9 @@ object UnitBlockCoercionImpl : UnitBlockCoercion<() -> Unit> {
|
||||
override fun uncoerce(block: () -> Unit): () -> Unit = block
|
||||
}
|
||||
|
||||
fun isFunction(obj: Any?): Boolean = obj is Function<*>
|
||||
fun isFunction0(obj: Any?): Boolean = obj is Function0<*>
|
||||
|
||||
abstract class MyAbstractList : List<Any?>
|
||||
|
||||
fun takeForwardDeclaredClass(obj: objcnames.classes.ForwardDeclaredClass) {}
|
||||
|
||||
@@ -386,6 +386,12 @@ func testLambda() throws {
|
||||
}
|
||||
try assertTrue(uncoercedUnitBlock() == Void())
|
||||
try assertEquals(actual: blockRuns, expected: 5)
|
||||
|
||||
let blockMustBeFunction0: @convention(block) () -> AnyObject? = { return nil }
|
||||
try assertTrue(ValuesKt.isFunction(obj: blockMustBeFunction0))
|
||||
try assertTrue(ValuesKt.isFunction0(obj: blockMustBeFunction0))
|
||||
try assertFalse(ValuesKt.isFunction(obj: NSObject()))
|
||||
try assertFalse(ValuesKt.isFunction0(obj: NSObject()))
|
||||
}
|
||||
|
||||
// -------- Tests for classes and interfaces -------
|
||||
|
||||
Reference in New Issue
Block a user