From 76d0b896afac7d2a1f2e87c760d91b80cfbbb5d0 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Wed, 20 May 2020 18:47:03 +0300 Subject: [PATCH] Add comments about exception handling to ObjCExport headers --- .../backend/konan/objcexport/MethodBridge.kt | 3 + .../objcexport/ObjCExportHeaderGenerator.kt | 40 +- .../backend/konan/objcexport/StubRenderer.kt | 8 + .../kotlin/backend/konan/objcexport/stubs.kt | 21 +- .../tests/objcexport/expectedLazy.h | 381 ++++++++++++++++++ .../tests/objcexport/throwsEmpty.kt | 6 + 6 files changed, 451 insertions(+), 8 deletions(-) create mode 100644 backend.native/tests/objcexport/throwsEmpty.kt diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/MethodBridge.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/MethodBridge.kt index cf7b36de49a..a7022504089 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/MethodBridge.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/MethodBridge.kt @@ -71,6 +71,9 @@ internal data class MethodBridge( MethodBridgeReceiver.Instance -> true } + + val returnsError: Boolean + get() = returnBridge is ReturnValue.WithError } internal fun MethodBridge.valueParametersAssociated( diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt index 7266d9c756b..83e505944f0 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt @@ -640,7 +640,9 @@ internal class ObjCExportTranslatorImpl( attributes.addIfNotNull(mapper.getDeprecation(method)?.toDeprecationAttribute()) } - return ObjCMethod(method, isInstanceMethod, returnType, selectorParts, parameters, attributes) + val comment = buildComment(method, baseMethodBridge) + + return ObjCMethod(method, isInstanceMethod, returnType, selectorParts, parameters, attributes, comment) } private fun splitSelector(selector: String): List { @@ -651,6 +653,42 @@ internal class ObjCExportTranslatorImpl( } } + private fun buildComment(method: FunctionDescriptor, bridge: MethodBridge): ObjCComment? { + if (method.isSuspend || bridge.returnsError) { + val effectiveThrows = getEffectiveThrows(method).toSet() + return when { + effectiveThrows.contains(throwableClassId) -> { + ObjCComment("@note This method converts all Kotlin exceptions to errors.") + } + + effectiveThrows.isNotEmpty() -> { + ObjCComment( + buildString { + append("@note This method converts instances of ") + effectiveThrows.joinTo(this) { it.relativeClassName.asString() } + append(" to errors.") + }, + "Other uncaught Kotlin exceptions are fatal." + ) + } + + else -> { + // Shouldn't happen though. + ObjCComment("@warning All uncaught Kotlin exceptions are fatal.") + } + } + } + + return null + } + + private val throwableClassId = ClassId.topLevel(KotlinBuiltIns.FQ_NAMES.throwable) + + private fun getEffectiveThrows(method: FunctionDescriptor): Sequence { + method.overriddenDescriptors.firstOrNull()?.let { return getEffectiveThrows(it) } + return getDefinedThrows(method).orEmpty() + } + private fun exportThrown(method: FunctionDescriptor) { getDefinedThrows(method) ?.mapNotNull { method.module.findClassAcrossModuleDependencies(it) } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/StubRenderer.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/StubRenderer.kt index 508cd6ce83b..76605186c7c 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/StubRenderer.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/StubRenderer.kt @@ -10,6 +10,14 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor object StubRenderer { fun render(stub: Stub<*>): List = collect { stub.run { + this.comment?.let { comment -> + +"" // Probably makes the output more readable. + +"/**" + comment.contentLines.forEach { + +" $it" + } + +"*/" + } when (this) { is ObjCProtocol -> { attributes.forEach { diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/stubs.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/stubs.kt index 6e1d2564f64..bc5bf4a6bef 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/stubs.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/stubs.kt @@ -10,7 +10,11 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.resolve.source.PsiSourceElement -abstract class Stub(val name: String) { +class ObjCComment(val contentLines: List) { + constructor(vararg contentLines: String) : this(contentLines.toList()) +} + +abstract class Stub(val name: String, val comment: ObjCComment? = null) { abstract val descriptor: D? open val psi: PsiElement? get() = ((descriptor as? DeclarationDescriptorWithSource)?.source as? PsiSourceElement)?.psi @@ -56,12 +60,15 @@ class ObjCInterfaceImpl( attributes: List = emptyList() ) : ObjCInterface(name, generics, categoryName, attributes) -class ObjCMethod(override val descriptor: DeclarationDescriptor?, - val isInstanceMethod: Boolean, - val returnType: ObjCType, - val selectors: List, - val parameters: List, - val attributes: List) : Stub(buildMethodName(selectors, parameters)) +class ObjCMethod( + override val descriptor: DeclarationDescriptor?, + val isInstanceMethod: Boolean, + val returnType: ObjCType, + val selectors: List, + val parameters: List, + val attributes: List, + comment: ObjCComment? = null +) : Stub(buildMethodName(selectors, parameters), comment) class ObjCParameter(name: String, override val descriptor: ParameterDescriptor?, diff --git a/backend.native/tests/objcexport/expectedLazy.h b/backend.native/tests/objcexport/expectedLazy.h index a9a3528029c..f037241b94e 100644 --- a/backend.native/tests/objcexport/expectedLazy.h +++ b/backend.native/tests/objcexport/expectedLazy.h @@ -142,6 +142,11 @@ __attribute__((swift_name("ContinuationHolder"))) __attribute__((swift_name("SuspendFun"))) @protocol KtSuspendFun @required + +/** + @note This method converts instances of CoroutineException, CancellationException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (void)suspendFunDoYield:(BOOL)doYield doThrow:(BOOL)doThrow completionHandler:(void (^)(KtInt * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("suspendFun(doYield:doThrow:completionHandler:)"))); @end; @@ -158,13 +163,49 @@ __attribute__((swift_name("ResultHolder"))) __attribute__((swift_name("SuspendBridge"))) @protocol KtSuspendBridge @required + +/** + @note This method converts instances of CancellationException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (void)intValue:(id _Nullable)value completionHandler:(void (^)(KtInt * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("int(value:completionHandler:)"))); + +/** + @note This method converts instances of CancellationException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (void)intAsAnyValue:(id _Nullable)value completionHandler:(void (^)(id _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:(id _Nullable)value completionHandler:(void (^)(KtKotlinUnit * _Nullable, 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:(id _Nullable)value completionHandler:(void (^)(id _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("unitAsAny(value:completionHandler:)"))); + +/** + @note This method converts all Kotlin exceptions to errors. +*/ - (void)nothingValue:(id _Nullable)value completionHandler:(void (^)(KtKotlinNothing * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("nothing(value:completionHandler:)"))); + +/** + @note This method converts all Kotlin exceptions to errors. +*/ - (void)nothingAsIntValue:(id _Nullable)value completionHandler:(void (^)(KtInt * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("nothingAsInt(value:completionHandler:)"))); + +/** + @note This method converts all Kotlin exceptions to errors. +*/ - (void)nothingAsAnyValue:(id _Nullable)value completionHandler:(void (^)(id _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("nothingAsAny(value:completionHandler:)"))); + +/** + @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:)"))); @end; @@ -172,10 +213,32 @@ __attribute__((swift_name("AbstractSuspendBridge"))) @interface KtAbstractSuspendBridge : KtBase - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); + +/** + @note This method converts instances of CancellationException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (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)unitAsAnyValue:(KtInt *)value completionHandler:(void (^)(KtKotlinUnit * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("unitAsAny(value:completionHandler:)"))); + +/** + @note This method converts all Kotlin exceptions to errors. +*/ - (void)nothingAsIntValue:(KtInt *)value completionHandler:(void (^)(KtKotlinNothing * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("nothingAsInt(value:completionHandler:)"))); + +/** + @note This method converts all Kotlin exceptions to errors. +*/ - (void)nothingAsAnyValue:(KtInt *)value completionHandler:(void (^)(KtKotlinNothing * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("nothingAsAny(value:completionHandler:)"))); + +/** + @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:)"))); @end; @@ -190,19 +253,58 @@ __attribute__((swift_name("ThrowCancellationExceptionImpl"))) @interface KtThrowCancellationExceptionImpl : KtThrowCancellationException - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); + +/** + @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:)"))); @end; __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("CoroutinesKt"))) @interface KtCoroutinesKt : KtBase + +/** + @note This method converts instances of CancellationException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ + (void)suspendFunWithCompletionHandler:(void (^)(KtInt * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("suspendFun(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, 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)suspendFunAsyncResult:(id _Nullable)result continuationHolder:(KtContinuationHolder *)continuationHolder completionHandler:(void (^)(id _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("suspendFunAsync(result:continuationHolder:completionHandler:)"))); + +/** + @note This method converts instances of CoroutineException, CancellationException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ + (BOOL)throwExceptionException:(KtKotlinThrowable *)exception error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("throwException(exception:)"))); + (void)callSuspendFunSuspendFun:(id)suspendFun doYield:(BOOL)doYield doThrow:(BOOL)doThrow resultHolder:(KtResultHolder *)resultHolder __attribute__((swift_name("callSuspendFun(suspendFun:doYield:doThrow:resultHolder:)"))); + +/** + @note This method converts instances of CoroutineException, CancellationException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ + (void)callSuspendFun2SuspendFun:(id)suspendFun doYield:(BOOL)doYield doThrow:(BOOL)doThrow completionHandler:(void (^)(KtInt * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("callSuspendFun2(suspendFun:doYield:doThrow:completionHandler:)"))); + +/** + @note This method converts all Kotlin exceptions to errors. +*/ + (BOOL)callSuspendBridgeBridge:(KtAbstractSuspendBridge *)bridge resultHolder:(KtResultHolder *)resultHolder error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("callSuspendBridge(bridge:resultHolder:)"))); + +/** + @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:)"))); @end; @@ -260,6 +362,16 @@ __attribute__((swift_name("LibraryKt"))) + (NSString *)readDataFromLibraryEnumInput:(KtE *)input __attribute__((swift_name("readDataFromLibraryEnum(input:)"))); @end; +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("ThrowsEmptyKt"))) +@interface KtThrowsEmptyKt : KtBase + +/** + @warning All uncaught Kotlin exceptions are fatal. +*/ ++ (BOOL)throwsEmptyAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("throwsEmpty()"))); +@end; + __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("DelegateClass"))) @interface KtDelegateClass : KtBase @@ -418,69 +530,269 @@ __attribute__((swift_name("MyError"))) __attribute__((swift_name("SwiftOverridableMethodsWithThrows"))) @protocol KtSwiftOverridableMethodsWithThrows @required + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (BOOL)unitAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("unit()"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (BOOL)nothingAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("nothing()"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (id _Nullable)anyAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("any()"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (KtInt *(^ _Nullable)(void))blockAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("block()"))); @end; __attribute__((swift_name("MethodsWithThrows"))) @protocol KtMethodsWithThrows @required + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (KtKotlinNothing * _Nullable)nothingNAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("nothingN()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (id _Nullable)anyNAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("anyN()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (KtInt *(^ _Nullable)(void))blockNAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("blockN()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (void * _Nullable)pointerAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("pointer()"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (void * _Nullable)pointerNAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("pointerN()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (int32_t)intAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("int()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (KtLong * _Nullable)longNAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("longN()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (double)doubleAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("double()"))) __attribute__((swift_error(nonnull_error))); @end; __attribute__((swift_name("MethodsWithThrowsUnitCaller"))) @protocol KtMethodsWithThrowsUnitCaller @required + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (BOOL)callMethods:(id)methods error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("call(methods:)"))); @end; __attribute__((swift_name("Throwing"))) @interface KtThrowing : KtBase + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (instancetype _Nullable)initWithDoThrow:(BOOL)doThrow error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("init(doThrow:)"))) __attribute__((objc_designated_initializer)); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (BOOL)unitAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("unit()"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (BOOL)nothingAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("nothing()"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (KtKotlinNothing * _Nullable)nothingNAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("nothingN()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (id _Nullable)anyAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("any()"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (id _Nullable)anyNAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("anyN()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (KtInt *(^ _Nullable)(void))blockAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("block()"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (KtInt *(^ _Nullable)(void))blockNAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("blockN()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (void * _Nullable)pointerAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("pointer()"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (void * _Nullable)pointerNAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("pointerN()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (int32_t)intAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("int()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (KtLong * _Nullable)longNAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("longN()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (double)doubleAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("double()"))) __attribute__((swift_error(nonnull_error))); @end; __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("NotThrowing"))) @interface KtNotThrowing : KtBase + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (instancetype _Nullable)initAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (BOOL)unitAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("unit()"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (BOOL)nothingAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("nothing()"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (KtKotlinNothing * _Nullable)nothingNAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("nothingN()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (id _Nullable)anyAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("any()"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (id _Nullable)anyNAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("anyN()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (KtInt *(^ _Nullable)(void))blockAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("block()"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (KtInt *(^ _Nullable)(void))blockNAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("blockN()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (void * _Nullable)pointerAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("pointer()"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (void * _Nullable)pointerNAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("pointerN()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (int32_t)intAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("int()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (KtLong * _Nullable)longNAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("longN()"))) __attribute__((swift_error(nonnull_error))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (double)doubleAndReturnError:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("double()"))) __attribute__((swift_error(nonnull_error))); @end; __attribute__((swift_name("ThrowsWithBridgeBase"))) @protocol KtThrowsWithBridgeBase @required + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (id _Nullable)plusOneX:(int32_t)x error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("plusOne(x:)"))); @end; @@ -488,6 +800,11 @@ __attribute__((swift_name("ThrowsWithBridge"))) @interface KtThrowsWithBridge : KtBase - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (KtInt * _Nullable)plusOneX:(int32_t)x error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("plusOne(x:)"))); @end; @@ -1256,8 +1573,23 @@ __attribute__((swift_name("TestStringConversion"))) __attribute__((swift_name("GH3825"))) @protocol KtGH3825 @required + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (BOOL)call0AndReturnError:(NSError * _Nullable * _Nullable)error callback:(KtBoolean *(^)(void))callback __attribute__((swift_name("call0(callback:)"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (BOOL)call1DoThrow:(BOOL)doThrow error:(NSError * _Nullable * _Nullable)error callback:(void (^)(void))callback __attribute__((swift_name("call1(doThrow:callback:)"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (BOOL)call2Callback:(void (^)(void))callback doThrow:(BOOL)doThrow error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("call2(callback:doThrow:)"))); @end; @@ -1266,8 +1598,23 @@ __attribute__((swift_name("GH3825KotlinImpl"))) @interface KtGH3825KotlinImpl : KtBase - (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (BOOL)call0AndReturnError:(NSError * _Nullable * _Nullable)error callback:(KtBoolean *(^)(void))callback __attribute__((swift_name("call0(callback:)"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (BOOL)call1DoThrow:(BOOL)doThrow error:(NSError * _Nullable * _Nullable)error callback:(void (^)(void))callback __attribute__((swift_name("call1(doThrow:callback:)"))); + +/** + @note This method converts instances of MyException to errors. + Other uncaught Kotlin exceptions are fatal. +*/ - (BOOL)call2Callback:(void (^)(void))callback doThrow:(BOOL)doThrow error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("call2(callback:doThrow:)"))); @end; @@ -1332,12 +1679,42 @@ __attribute__((swift_name("ValuesKt"))) + (BOOL)isFrozenObj:(id)obj __attribute__((swift_name("isFrozen(obj:)"))); + (id)kotlinLambdaBlock:(id (^)(id))block __attribute__((swift_name("kotlinLambda(block:)"))); + (int64_t)multiplyInt:(int32_t)int_ long:(int64_t)long_ __attribute__((swift_name("multiply(int:long:)"))); + +/** + @note This method converts instances of MyException, MyError to errors. + Other uncaught Kotlin exceptions are fatal. +*/ + (BOOL)throwExceptionError:(BOOL)error error:(NSError * _Nullable * _Nullable)error_ __attribute__((swift_name("throwException(error:)"))); + +/** + @note This method converts all Kotlin exceptions to errors. +*/ + (KtKotlinObjCErrorException * _Nullable)testSwiftThrowingMethods:(id)methods error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("testSwiftThrowing(methods:)"))); + +/** + @note This method converts all Kotlin exceptions to errors. +*/ + (BOOL)testSwiftNotThrowingMethods:(id)methods error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("testSwiftNotThrowing(methods:)"))); + +/** + @note This method converts instances of MyError to errors. + Other uncaught Kotlin exceptions are fatal. +*/ + (BOOL)callUnitMethods:(id)methods error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("callUnit(methods:)"))); + +/** + @note This method converts all Kotlin exceptions to errors. +*/ + (BOOL)callUnitCallerCaller:(id)caller methods:(id)methods error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("callUnitCaller(caller:methods:)"))); + +/** + @note This method converts all Kotlin exceptions to errors. +*/ + (BOOL)testSwiftThrowingTest:(id)test flag:(BOOL)flag error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("testSwiftThrowing(test:flag:)"))); + +/** + @note This method converts all Kotlin exceptions to errors. +*/ + (BOOL)testSwiftNotThrowingTest:(id)test error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("testSwiftNotThrowing(test:)"))); + (id)same:(id)receiver __attribute__((swift_name("same(_:)"))); + (KtInt * _Nullable)callBase1:(id)base1 value:(KtInt * _Nullable)value __attribute__((swift_name("call(base1:value:)"))); @@ -1365,6 +1742,10 @@ __attribute__((swift_name("ValuesKt"))) + (int32_t)testAbstractInterfaceCallX:(id)x __attribute__((swift_name("testAbstractInterfaceCall(x:)"))); + (int32_t)testAbstractInterfaceCall2X:(id)x __attribute__((swift_name("testAbstractInterfaceCall2(x:)"))); + (void)fooA:(KtKotlinAtomicReference *)a __attribute__((swift_name("foo(a:)"))); + +/** + @note This method converts all Kotlin exceptions to errors. +*/ + (BOOL)testGH3825Gh3825:(id)gh3825 error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("testGH3825(gh3825:)"))); + (NSDictionary *)mapBoolean2String __attribute__((swift_name("mapBoolean2String()"))); + (NSDictionary *)mapByte2Short __attribute__((swift_name("mapByte2Short()"))); diff --git a/backend.native/tests/objcexport/throwsEmpty.kt b/backend.native/tests/objcexport/throwsEmpty.kt new file mode 100644 index 00000000000..1508b0e30ce --- /dev/null +++ b/backend.native/tests/objcexport/throwsEmpty.kt @@ -0,0 +1,6 @@ +package throwsEmpty + +// Suppressing compilation error. +// Only the generated comment is checked. +@Suppress("THROWS_LIST_EMPTY") +@Throws fun throwsEmpty() {}