Add test for SAM-converted lambdas passed to Obj-C
Based on https://youtrack.jetbrains.com/issue/KT-44799
This commit is contained in:
committed by
Vasily Levchenko
parent
ab36e919bc
commit
f7af8bc763
@@ -377,6 +377,19 @@ __attribute__((swift_name("EmptyEnum")))
|
|||||||
+ (KtKotlinArray<KtEmptyEnum *> *)values __attribute__((swift_name("values()")));
|
+ (KtKotlinArray<KtEmptyEnum *> *)values __attribute__((swift_name("values()")));
|
||||||
@end;
|
@end;
|
||||||
|
|
||||||
|
__attribute__((swift_name("FunInterface")))
|
||||||
|
@protocol KtFunInterface
|
||||||
|
@required
|
||||||
|
- (int32_t)run __attribute__((swift_name("run()")));
|
||||||
|
@end;
|
||||||
|
|
||||||
|
__attribute__((objc_subclassing_restricted))
|
||||||
|
__attribute__((swift_name("FunInterfacesKt")))
|
||||||
|
@interface KtFunInterfacesKt : KtBase
|
||||||
|
+ (id<KtFunInterface>)getObject __attribute__((swift_name("getObject()")));
|
||||||
|
+ (id<KtFunInterface>)getLambda __attribute__((swift_name("getLambda()")));
|
||||||
|
@end;
|
||||||
|
|
||||||
__attribute__((swift_name("FHolder")))
|
__attribute__((swift_name("FHolder")))
|
||||||
@interface KtFHolder : KtBase
|
@interface KtFHolder : KtBase
|
||||||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package funinterfaces
|
||||||
|
|
||||||
|
fun interface FunInterface {
|
||||||
|
fun run(): Int
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getObject(): FunInterface {
|
||||||
|
return object : FunInterface {
|
||||||
|
override fun run() = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getLambda(): FunInterface {
|
||||||
|
return FunInterface { 2 }
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import Kt
|
||||||
|
|
||||||
|
// Based on https://youtrack.jetbrains.com/issue/KT-44799.
|
||||||
|
private func testSAMConversion() throws {
|
||||||
|
try assertEquals(actual: FunInterfacesKt.getObject().run(), expected: 1)
|
||||||
|
try assertEquals(actual: FunInterfacesKt.getLambda().run(), expected: 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
class FunInterfacesTests : SimpleTestProvider {
|
||||||
|
override init() {
|
||||||
|
super.init()
|
||||||
|
|
||||||
|
test("TestSAMConversion", testSAMConversion)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user