Skip to content

Commit

Permalink
Make Objective-C blocks conform to kotlin.Function<*> interface (JetB…
Browse files Browse the repository at this point in the history
  • Loading branch information
SvyatoslavScherbina authored Oct 25, 2019
1 parent 61702a6 commit 1d18008
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions backend.native/tests/framework/values/expectedLazy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down
3 changes: 3 additions & 0 deletions backend.native/tests/framework/values/values.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
6 changes: 6 additions & 0 deletions backend.native/tests/framework/values/values.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 -------
Expand Down

0 comments on commit 1d18008

Please sign in to comment.