From b1a9715907beae08e159b1cf467b26527c47731a Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Wed, 19 Aug 2020 18:14:47 +0300 Subject: [PATCH] Handle newline character in deprecation message in ObjCExport #KT-39206 Fixed --- .../konan/objcexport/ObjCExportHeaderGenerator.kt | 1 + backend.native/tests/objcexport/expectedLazy.h | 12 ++++++++++++ backend.native/tests/objcexport/kt39206.kt | 14 ++++++++++++++ backend.native/tests/objcexport/kt39206.swift | 13 +++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 backend.native/tests/objcexport/kt39206.kt create mode 100644 backend.native/tests/objcexport/kt39206.swift 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 ca8e2794404..b4f11958c9f 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 @@ -1234,6 +1234,7 @@ private fun Deprecation.toDeprecationAttribute(): String { // TODO: consider avoiding code generation for unavailable. val message = this.message.orEmpty() + .replace("\n", "\\n") return "$attribute(\"$message\")" } diff --git a/backend.native/tests/objcexport/expectedLazy.h b/backend.native/tests/objcexport/expectedLazy.h index 8f13bc30c01..b168322dcc9 100644 --- a/backend.native/tests/objcexport/expectedLazy.h +++ b/backend.native/tests/objcexport/expectedLazy.h @@ -513,6 +513,18 @@ __attribute__((swift_name("Kt38641Kt"))) + (void)setOverrideVarDescriptionImpl:(id)impl newValue:(NSString *)newValue __attribute__((swift_name("setOverrideVarDescription(impl:newValue:)"))); @end; +__attribute__((swift_name("JsonConfiguration"))) +@interface KtJsonConfiguration : KtBase +- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)) __attribute__((unavailable("This class is deprecated for removal during serialization 1.0 API stabilization.\nFor configuring Json instances, the corresponding builder function can be used instead, e.g. instead of'Json(JsonConfiguration.Stable.copy(isLenient = true))' 'Json { isLenient = true }' should be used.\nInstead of storing JsonConfiguration instances of the code, Json instances can be used directly:'Json(MyJsonConfiguration.copy(prettyPrint = true))' can be replaced with 'Json(from = MyApplicationJson) { prettyPrint = true }'"))); ++ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); +@end; + +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("Kt39206Kt"))) +@interface KtKt39206Kt : KtBase ++ (int32_t)myFunc __attribute__((swift_name("myFunc()"))) __attribute__((deprecated("Don't call this\nPlease"))); +@end; + __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("LibraryKt"))) @interface KtLibraryKt : KtBase diff --git a/backend.native/tests/objcexport/kt39206.kt b/backend.native/tests/objcexport/kt39206.kt new file mode 100644 index 00000000000..50e4529b505 --- /dev/null +++ b/backend.native/tests/objcexport/kt39206.kt @@ -0,0 +1,14 @@ +// See https://youtrack.jetbrains.com/issue/KT-39206. +@Deprecated("Don't call this\nPlease") +fun myFunc() = 17 + +// See https://youtrack.jetbrains.com/issue/KT-41193. +@Deprecated( + level = DeprecationLevel.ERROR, + message = "This class is deprecated for removal during serialization 1.0 API stabilization.\n" + + "For configuring Json instances, the corresponding builder function can be used instead, e.g. instead of" + + "'Json(JsonConfiguration.Stable.copy(isLenient = true))' 'Json { isLenient = true }' should be used.\n" + + "Instead of storing JsonConfiguration instances of the code, Json instances can be used directly:" + + "'Json(MyJsonConfiguration.copy(prettyPrint = true))' can be replaced with 'Json(from = MyApplicationJson) { prettyPrint = true }'" +) +public open class JsonConfiguration \ No newline at end of file diff --git a/backend.native/tests/objcexport/kt39206.swift b/backend.native/tests/objcexport/kt39206.swift new file mode 100644 index 00000000000..bde00f72ea4 --- /dev/null +++ b/backend.native/tests/objcexport/kt39206.swift @@ -0,0 +1,13 @@ +import Kt + +private func test1() throws { + try assertEquals(actual: Kt39206Kt.myFunc(), expected: 17) +} + +class Kt39206Tests : SimpleTestProvider { + override init() { + super.init() + + test("Test1", test1) + } +} \ No newline at end of file