ObjCExport: remove KotlinUnit from suspend funs returning Unit (#4635)

With `unitSuspendFunctionObjCExport=proper` binary option,
for Unit-returning suspend functions ObjCExport now generates
completion handlers without redundant `KotlinUnit*` result parameter.

So Swift (5.5+) can import these functions as Void-returning async
functions.

^KT-47399 Fixed
This commit is contained in:
Nikolay Kasyanov
2021-11-18 08:01:33 +01:00
committed by GitHub
parent 7f6afcabf1
commit 4dcfd38236
23 changed files with 3093 additions and 64 deletions
@@ -5321,7 +5321,7 @@ if (isAppleTarget(project)) {
framework(frameworkName) {
sources = ['objcexport']
library = libraryName
opts = ["-Xemit-lazy-objc-header=$lazyHeader", "-Xexport-kdoc", "-Xbundle-id=foo.bar"]
opts = ["-Xemit-lazy-objc-header=$lazyHeader", "-Xexport-kdoc", "-Xbundle-id=foo.bar", "-Xbinary=unitSuspendFunctionObjCExport=proper"]
}
swiftSources = ['objcexport']
if (isNoopGC) {
@@ -5375,7 +5375,7 @@ if (isAppleTarget(project)) {
sources = ['objcexport']
artifact = frameworkArtifactName
library = libraryName
opts = ["-Xemit-lazy-objc-header=$lazyHeader", "-Xno-objc-generics"]
opts = ["-Xemit-lazy-objc-header=$lazyHeader", "-Xno-objc-generics", "-Xbinary=unitSuspendFunctionObjCExport=proper"]
}
swiftSources = ['objcexport']
swiftExtraOpts = [ '-D', 'NO_GENERICS' ]
@@ -5384,6 +5384,61 @@ if (isAppleTarget(project)) {
}
}
frameworkTest('testObjCExportLegacySuspendUnit') {
final String frameworkName = 'KtLegacySuspendUnit'
final String frameworkArtifactName = 'Kt'
final String dir = "$testOutputFramework/testObjCExportLegacySuspendUnit"
final File lazyHeader = file("$dir/$target-lazy.h")
doLast {
final String expectedLazyHeaderName = "expectedLazyLegacySuspendUnit.h"
final String expectedLazyHeaderDir = file("objcexport/")
final File expectedLazyHeader = new File(expectedLazyHeaderDir, expectedLazyHeaderName)
if (expectedLazyHeader.readLines() != lazyHeader.readLines()) {
exec {
commandLine 'diff', '-u', expectedLazyHeader, lazyHeader
ignoreExitValue = true
}
copy {
from(lazyHeader)
into(expectedLazyHeaderDir)
rename { expectedLazyHeaderName }
}
throw new Error("$expectedLazyHeader file patched;\nre-run the test and don't forget to commit the patch")
}
}
def libraryName = frameworkName + "Library"
konanArtifacts {
library(libraryName, targets: [target.name]) {
srcDir "objcexport/library"
artifactName "test-library"
if (!useCustomDist) {
dependsOn ":${target.name}CrossDistRuntime", ':distCompiler'
}
extraOpts "-Xshort-module-name=MyLibrary"
extraOpts "-module-name", "org.jetbrains.kotlin.native.test-library"
}
}
framework(frameworkName) {
sources = ['objcexport']
artifact = frameworkArtifactName
library = libraryName
opts = ["-Xemit-lazy-objc-header=$lazyHeader"]
}
swiftSources = ['objcexport']
swiftExtraOpts = [ '-D', 'LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT' ]
if (isNoopGC) {
swiftExtraOpts += ["-D", "NOOP_GC"]
}
}
frameworkTest('testObjCExportStatic') {
final String frameworkName = 'KtStatic'
final String frameworkArtifactName = 'Kt'
@@ -5410,6 +5465,7 @@ if (isAppleTarget(project)) {
artifact = frameworkArtifactName
library = libraryName
isStatic = true
opts = ["-Xbinary=unitSuspendFunctionObjCExport=proper"]
}
swiftSources = ['objcexport']
if (isNoopGC) {
@@ -15,6 +15,7 @@ import kotlin.test.*
class CoroutineException : Throwable()
suspend fun suspendFun() = 42
suspend fun unitSuspendFun() = Unit
@Throws(CoroutineException::class, CancellationException::class)
suspend fun suspendFun(result: Any?, doSuspend: Boolean, doThrow: Boolean): Any? {
@@ -30,6 +31,18 @@ suspend fun suspendFun(result: Any?, doSuspend: Boolean, doThrow: Boolean): Any?
return result
}
@Throws(CoroutineException::class, CancellationException::class)
suspend fun unitSuspendFun(doSuspend: Boolean, doThrow: Boolean) {
if (doSuspend) {
suspendCoroutineUninterceptedOrReturn<Unit> {
it.resume(Unit)
COROUTINE_SUSPENDED
}
}
if (doThrow) throw CoroutineException()
}
class ContinuationHolder<T> {
internal lateinit var continuation: Continuation<T>
@@ -96,6 +109,7 @@ interface SuspendBridge<T> {
suspend fun unit(value: T): Unit
suspend fun unitAsAny(value: T): Any?
suspend fun nullableUnit(value: T): Unit?
@Throws(Throwable::class) suspend fun nothing(value: T): Nothing
@Throws(Throwable::class) suspend fun nothingAsInt(value: T): Int
@@ -106,7 +120,9 @@ interface SuspendBridge<T> {
abstract class AbstractSuspendBridge : SuspendBridge<Int> {
override suspend fun intAsAny(value: Int): Int = TODO()
override suspend fun unit(value: Int): Unit = TODO()
override suspend fun unitAsAny(value: Int): Unit = TODO()
override suspend fun nullableUnit(value: Int): Unit? = TODO()
override suspend fun nothingAsInt(value: Int): Nothing = TODO()
override suspend fun nothingAsAny(value: Int): Nothing = TODO()
@@ -116,21 +132,25 @@ abstract class AbstractSuspendBridge : SuspendBridge<Int> {
private suspend fun callSuspendBridgeImpl(bridge: SuspendBridge<Int>) {
assertEquals(1, bridge.intAsAny(1))
assertSame(Unit, bridge.unitAsAny(2))
assertSame(Unit, bridge.unit(2))
assertSame(Unit, bridge.unitAsAny(3))
assertSame(Unit, bridge.nullableUnit(4))
assertFailsWith<ObjCErrorException> { bridge.nothingAsInt(3) }
assertFailsWith<ObjCErrorException> { bridge.nothingAsAny(4) }
assertFailsWith<ObjCErrorException> { bridge.nothingAsUnit(5) }
assertFailsWith<ObjCErrorException> { bridge.nothingAsInt(5) }
assertFailsWith<ObjCErrorException> { bridge.nothingAsAny(6) }
assertFailsWith<ObjCErrorException> { bridge.nothingAsUnit(7) }
}
private suspend fun callAbstractSuspendBridgeImpl(bridge: AbstractSuspendBridge) {
assertEquals(6, bridge.intAsAny(6))
assertEquals(8, bridge.intAsAny(8))
assertSame(Unit, bridge.unitAsAny(7))
assertSame(Unit, bridge.unit(9))
assertSame(Unit, bridge.unitAsAny(10))
assertSame(Unit, bridge.nullableUnit(11))
assertFailsWith<ObjCErrorException> { bridge.nothingAsInt(8) }
assertFailsWith<ObjCErrorException> { bridge.nothingAsAny(9) }
assertFailsWith<ObjCErrorException> { bridge.nothingAsUnit(10) }
assertFailsWith<ObjCErrorException> { bridge.nothingAsInt(12) }
assertFailsWith<ObjCErrorException> { bridge.nothingAsAny(13) }
assertFailsWith<ObjCErrorException> { bridge.nothingAsUnit(14) }
}
@Throws(Throwable::class)
@@ -21,6 +21,33 @@ private func testCallSimple() throws {
try assertNil(error)
}
private func testUnitCallSimple() throws {
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
var result: KotlinUnit? = nil
#endif
var error: Error? = nil
var completionCalled = 0
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
CoroutinesKt.unitSuspendFun { _result, _error in
completionCalled += 1
result = _result
error = _error
}
#else
CoroutinesKt.unitSuspendFun { _error in
completionCalled += 1
error = _error
}
#endif
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
try assertSame(actual: result, expected: KotlinUnit.shared)
#endif
try assertEquals(actual: completionCalled, expected: 1)
try assertNil(error)
}
private func testCallSuspendFun(doSuspend: Bool, doThrow: Bool) throws {
class C {}
let expectedResult = C()
@@ -46,6 +73,39 @@ private func testCallSuspendFun(doSuspend: Bool, doThrow: Bool) throws {
}
}
private func testCallUnitSuspendFun(doSuspend: Bool, doThrow: Bool) throws {
var completionCalled = 0
var result: AnyObject? = nil
var error: Error? = nil
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
CoroutinesKt.unitSuspendFun(doSuspend: doSuspend, doThrow: doThrow) { _result, _error in
completionCalled += 1
result = _result as AnyObject?
error = _error
}
#else
CoroutinesKt.unitSuspendFun(doSuspend: doSuspend, doThrow: doThrow) { _error in
completionCalled += 1
error = _error
}
#endif
try assertEquals(actual: completionCalled, expected: 1)
if doThrow {
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
try assertNil(result)
#endif
try assertTrue(error?.kotlinException is CoroutineException)
} else {
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
try assertSame(actual: result, expected: KotlinUnit.shared)
#endif
try assertNil(error)
}
}
private func testSuspendFuncAsync(doThrow: Bool) throws {
var completionCalled = 0
var result: AnyObject? = nil
@@ -91,6 +151,11 @@ private func testCall() throws {
try testCallSuspendFun(doSuspend: true, doThrow: true)
try testCallSuspendFun(doSuspend: false, doThrow: true)
try testCallUnitSuspendFun(doSuspend: true, doThrow: false)
try testCallUnitSuspendFun(doSuspend: false, doThrow: false)
try testCallUnitSuspendFun(doSuspend: true, doThrow: true)
try testCallUnitSuspendFun(doSuspend: false, doThrow: true)
try testSuspendFuncAsync(doThrow: false)
try testSuspendFuncAsync(doThrow: true)
}
@@ -237,10 +302,24 @@ private class SwiftSuspendBridge : AbstractSuspendBridge {
completionHandler(value, nil)
}
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
override func unit(value: KotlinInt, completionHandler: @escaping (KotlinUnit?, Error?) -> Void) {
completionHandler(KotlinUnit(), nil)
}
#else
override func unit(value: KotlinInt, completionHandler: @escaping (Error?) -> Void) {
completionHandler(nil)
}
#endif
override func unitAsAny(value: KotlinInt, completionHandler: @escaping (KotlinUnit?, Error?) -> Void) {
completionHandler(KotlinUnit(), nil)
}
override func nullableUnit(value: KotlinInt, completionHandler: @escaping (KotlinUnit?, Error?) -> Void) {
completionHandler(KotlinUnit(), nil)
}
override func nothingAsInt(value: KotlinInt, completionHandler: @escaping (KotlinNothing?, Error?) -> Void) {
completionHandler(nil, E())
}
@@ -249,9 +328,15 @@ private class SwiftSuspendBridge : AbstractSuspendBridge {
completionHandler(nil, E())
}
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
override func nothingAsUnit(value: KotlinInt, completionHandler: @escaping (KotlinNothing?, Error?) -> Void) {
completionHandler(nil, E())
}
#else
override func nothingAsUnit(value: KotlinInt, completionHandler: @escaping (Error?) -> Void) {
completionHandler(E())
}
#endif
}
private func testBridges() throws {
@@ -268,34 +353,52 @@ private func testBridges() throws {
}
private func testImplicitThrows1() throws {
var result: KotlinUnit? = nil
var error: Error? = nil
var completionCalled = 0
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
var result: KotlinUnit? = nil
CoroutinesKt.throwCancellationException { _result, _error in
completionCalled += 1
result = _result
error = _error
}
try assertEquals(actual: completionCalled, expected: 1)
try assertNil(result)
#else
CoroutinesKt.throwCancellationException { _error in
completionCalled += 1
error = _error
}
#endif
try assertEquals(actual: completionCalled, expected: 1)
try assertTrue(error?.kotlinException is KotlinCancellationException)
}
private func testImplicitThrows2() throws {
var result: KotlinUnit? = nil
var error: Error? = nil
var completionCalled = 0
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
var result: KotlinUnit? = nil
ThrowCancellationExceptionImpl().throwCancellationException { _result, _error in
completionCalled += 1
result = _result
error = _error
completionCalled += 1
result = _result
error = _error
}
try assertEquals(actual: completionCalled, expected: 1)
try assertNil(result)
#else
ThrowCancellationExceptionImpl().throwCancellationException { _error in
completionCalled += 1
error = _error
}
#endif
try assertEquals(actual: completionCalled, expected: 1)
try assertTrue(error?.kotlinException is KotlinCancellationException)
}
@@ -369,6 +472,7 @@ class CoroutinesTests : SimpleTestProvider {
super.init()
test("TestCallSimple", testCallSimple)
test("TestCallUnitSimple", testUnitCallSimple)
test("TestCall", testCall)
test("TestCallChain", testCallChain)
test("TestOverride", testOverride)
@@ -180,7 +180,7 @@ __attribute__((swift_name("SuspendBridge")))
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
- (void)unitValue:(id _Nullable)value completionHandler:(void (^)(KtKotlinUnit * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("unit(value:completionHandler:)")));
- (void)unitValue:(id _Nullable)value completionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("unit(value:completionHandler:)")));
/**
@note This method converts instances of CancellationException to errors.
@@ -188,6 +188,12 @@ __attribute__((swift_name("SuspendBridge")))
*/
- (void)unitAsAnyValue:(id _Nullable)value completionHandler:(void (^)(id _Nullable_result, NSError * _Nullable))completionHandler __attribute__((swift_name("unitAsAny(value:completionHandler:)")));
/**
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
- (void)nullableUnitValue:(id _Nullable)value completionHandler:(void (^)(KtKotlinUnit * _Nullable_result, NSError * _Nullable))completionHandler __attribute__((swift_name("nullableUnit(value:completionHandler:)")));
/**
@note This method converts all Kotlin exceptions to errors.
*/
@@ -206,7 +212,7 @@ __attribute__((swift_name("SuspendBridge")))
/**
@note This method converts all Kotlin exceptions to errors.
*/
- (void)nothingAsUnitValue:(id _Nullable)value completionHandler:(void (^)(KtKotlinUnit * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("nothingAsUnit(value:completionHandler:)")));
- (void)nothingAsUnitValue:(id _Nullable)value completionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("nothingAsUnit(value:completionHandler:)")));
@end;
__attribute__((swift_name("AbstractSuspendBridge")))
@@ -220,12 +226,24 @@ __attribute__((swift_name("AbstractSuspendBridge")))
*/
- (void)intAsAnyValue:(KtInt *)value completionHandler:(void (^)(KtInt * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("intAsAny(value:completionHandler:)")));
/**
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
- (void)unitValue:(KtInt *)value completionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("unit(value:completionHandler:)")));
/**
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
- (void)unitAsAnyValue:(KtInt *)value completionHandler:(void (^)(KtKotlinUnit * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("unitAsAny(value:completionHandler:)")));
/**
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
- (void)nullableUnitValue:(KtInt *)value completionHandler:(void (^)(KtKotlinUnit * _Nullable_result, NSError * _Nullable))completionHandler __attribute__((swift_name("nullableUnit(value:completionHandler:)")));
/**
@note This method converts all Kotlin exceptions to errors.
*/
@@ -239,7 +257,7 @@ __attribute__((swift_name("AbstractSuspendBridge")))
/**
@note This method converts all Kotlin exceptions to errors.
*/
- (void)nothingAsUnitValue:(KtInt *)value completionHandler:(void (^)(KtKotlinNothing * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("nothingAsUnit(value:completionHandler:)")));
- (void)nothingAsUnitValue:(KtInt *)value completionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("nothingAsUnit(value:completionHandler:)")));
@end;
__attribute__((swift_name("ThrowCancellationException")))
@@ -258,7 +276,7 @@ __attribute__((swift_name("ThrowCancellationExceptionImpl")))
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
- (void)throwCancellationExceptionWithCompletionHandler:(void (^)(KtKotlinUnit * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("throwCancellationException(completionHandler:)")));
- (void)throwCancellationExceptionWithCompletionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("throwCancellationException(completionHandler:)")));
@end;
__attribute__((objc_subclassing_restricted))
@@ -271,12 +289,24 @@ __attribute__((swift_name("CoroutinesKt")))
*/
+ (void)suspendFunWithCompletionHandler:(void (^)(KtInt * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("suspendFun(completionHandler:)")));
/**
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
+ (void)unitSuspendFunWithCompletionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("unitSuspendFun(completionHandler:)")));
/**
@note This method converts instances of CoroutineException, CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
+ (void)suspendFunResult:(id _Nullable)result doSuspend:(BOOL)doSuspend doThrow:(BOOL)doThrow completionHandler:(void (^)(id _Nullable_result, NSError * _Nullable))completionHandler __attribute__((swift_name("suspendFun(result:doSuspend:doThrow:completionHandler:)")));
/**
@note This method converts instances of CoroutineException, CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
+ (void)unitSuspendFunDoSuspend:(BOOL)doSuspend doThrow:(BOOL)doThrow completionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("unitSuspendFun(doSuspend:doThrow:completionHandler:)")));
/**
@note This method converts instances of CoroutineException, CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
@@ -305,7 +335,7 @@ __attribute__((swift_name("CoroutinesKt")))
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
+ (void)throwCancellationExceptionWithCompletionHandler:(void (^)(KtKotlinUnit * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("throwCancellationException(completionHandler:)")));
+ (void)throwCancellationExceptionWithCompletionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("throwCancellationException(completionHandler:)")));
+ (id<KtKotlinSuspendFunction0>)getSuspendLambda0 __attribute__((swift_name("getSuspendLambda0()")));
+ (id<KtKotlinSuspendFunction0>)getSuspendCallableReference0 __attribute__((swift_name("getSuspendCallableReference0()")));
+ (id<KtKotlinSuspendFunction1>)getSuspendLambda1 __attribute__((swift_name("getSuspendLambda1()")));
@@ -1191,7 +1221,7 @@ __attribute__((swift_name("ThrowsThrowableAsErrorSuspend")))
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
- (void)throwErrorWithCompletionHandler:(void (^)(KtKotlinUnit * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("throwError(completionHandler:)")));
- (void)throwErrorWithCompletionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("throwError(completionHandler:)")));
@end;
__attribute__((objc_subclassing_restricted))
File diff suppressed because it is too large Load Diff
@@ -180,7 +180,7 @@ __attribute__((swift_name("SuspendBridge")))
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
- (void)unitValue:(id _Nullable)value completionHandler:(void (^)(KtKotlinUnit * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("unit(value:completionHandler:)")));
- (void)unitValue:(id _Nullable)value completionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("unit(value:completionHandler:)")));
/**
@note This method converts instances of CancellationException to errors.
@@ -188,6 +188,12 @@ __attribute__((swift_name("SuspendBridge")))
*/
- (void)unitAsAnyValue:(id _Nullable)value completionHandler:(void (^)(id _Nullable_result, NSError * _Nullable))completionHandler __attribute__((swift_name("unitAsAny(value:completionHandler:)")));
/**
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
- (void)nullableUnitValue:(id _Nullable)value completionHandler:(void (^)(KtKotlinUnit * _Nullable_result, NSError * _Nullable))completionHandler __attribute__((swift_name("nullableUnit(value:completionHandler:)")));
/**
@note This method converts all Kotlin exceptions to errors.
*/
@@ -206,7 +212,7 @@ __attribute__((swift_name("SuspendBridge")))
/**
@note This method converts all Kotlin exceptions to errors.
*/
- (void)nothingAsUnitValue:(id _Nullable)value completionHandler:(void (^)(KtKotlinUnit * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("nothingAsUnit(value:completionHandler:)")));
- (void)nothingAsUnitValue:(id _Nullable)value completionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("nothingAsUnit(value:completionHandler:)")));
@end;
__attribute__((swift_name("AbstractSuspendBridge")))
@@ -220,12 +226,24 @@ __attribute__((swift_name("AbstractSuspendBridge")))
*/
- (void)intAsAnyValue:(KtInt *)value completionHandler:(void (^)(KtInt * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("intAsAny(value:completionHandler:)")));
/**
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
- (void)unitValue:(KtInt *)value completionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("unit(value:completionHandler:)")));
/**
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
- (void)unitAsAnyValue:(KtInt *)value completionHandler:(void (^)(KtKotlinUnit * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("unitAsAny(value:completionHandler:)")));
/**
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
- (void)nullableUnitValue:(KtInt *)value completionHandler:(void (^)(KtKotlinUnit * _Nullable_result, NSError * _Nullable))completionHandler __attribute__((swift_name("nullableUnit(value:completionHandler:)")));
/**
@note This method converts all Kotlin exceptions to errors.
*/
@@ -239,7 +257,7 @@ __attribute__((swift_name("AbstractSuspendBridge")))
/**
@note This method converts all Kotlin exceptions to errors.
*/
- (void)nothingAsUnitValue:(KtInt *)value completionHandler:(void (^)(KtKotlinNothing * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("nothingAsUnit(value:completionHandler:)")));
- (void)nothingAsUnitValue:(KtInt *)value completionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("nothingAsUnit(value:completionHandler:)")));
@end;
__attribute__((swift_name("ThrowCancellationException")))
@@ -258,7 +276,7 @@ __attribute__((swift_name("ThrowCancellationExceptionImpl")))
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
- (void)throwCancellationExceptionWithCompletionHandler:(void (^)(KtKotlinUnit * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("throwCancellationException(completionHandler:)")));
- (void)throwCancellationExceptionWithCompletionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("throwCancellationException(completionHandler:)")));
@end;
__attribute__((objc_subclassing_restricted))
@@ -271,12 +289,24 @@ __attribute__((swift_name("CoroutinesKt")))
*/
+ (void)suspendFunWithCompletionHandler:(void (^)(KtInt * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("suspendFun(completionHandler:)")));
/**
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
+ (void)unitSuspendFunWithCompletionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("unitSuspendFun(completionHandler:)")));
/**
@note This method converts instances of CoroutineException, CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
+ (void)suspendFunResult:(id _Nullable)result doSuspend:(BOOL)doSuspend doThrow:(BOOL)doThrow completionHandler:(void (^)(id _Nullable_result, NSError * _Nullable))completionHandler __attribute__((swift_name("suspendFun(result:doSuspend:doThrow:completionHandler:)")));
/**
@note This method converts instances of CoroutineException, CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
+ (void)unitSuspendFunDoSuspend:(BOOL)doSuspend doThrow:(BOOL)doThrow completionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("unitSuspendFun(doSuspend:doThrow:completionHandler:)")));
/**
@note This method converts instances of CoroutineException, CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
@@ -305,7 +335,7 @@ __attribute__((swift_name("CoroutinesKt")))
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
+ (void)throwCancellationExceptionWithCompletionHandler:(void (^)(KtKotlinUnit * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("throwCancellationException(completionHandler:)")));
+ (void)throwCancellationExceptionWithCompletionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("throwCancellationException(completionHandler:)")));
+ (id<KtKotlinSuspendFunction0>)getSuspendLambda0 __attribute__((swift_name("getSuspendLambda0()")));
+ (id<KtKotlinSuspendFunction0>)getSuspendCallableReference0 __attribute__((swift_name("getSuspendCallableReference0()")));
+ (id<KtKotlinSuspendFunction1>)getSuspendLambda1 __attribute__((swift_name("getSuspendLambda1()")));
@@ -1133,7 +1163,7 @@ __attribute__((swift_name("ThrowsThrowableAsErrorSuspend")))
@note This method converts instances of CancellationException to errors.
Other uncaught Kotlin exceptions are fatal.
*/
- (void)throwErrorWithCompletionHandler:(void (^)(KtKotlinUnit * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("throwError(completionHandler:)")));
- (void)throwErrorWithCompletionHandler:(void (^)(NSError * _Nullable))completionHandler __attribute__((swift_name("throwError(completionHandler:)")));
@end;
__attribute__((objc_subclassing_restricted))
@@ -38,9 +38,15 @@ private class ThrowsThrowableAsErrorSuspendImpl : ThrowsThrowableAsErrorSuspend
self.throwable = throwable
}
#if LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT
func throwError(completionHandler: @escaping (KotlinUnit?, Error?) -> Void) {
completionHandler(nil, throwable.asError())
}
#else
func throwError(completionHandler: @escaping (Error?) -> Void) {
completionHandler(throwable.asError())
}
#endif
}
class ThrowableAsErrorTests : SimpleTestProvider {