From 0831ca7e8750ef8d7395d45a092f6f2bd0a4eb3c Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Mon, 24 Jun 2019 11:22:45 +0300 Subject: [PATCH] Fix property clash when producing framework --- .../konan/objcexport/ObjCExportNamer.kt | 4 ++++ .../tests/framework/values/expectedLazy.h | 22 +++++++++++++++++++ .../tests/framework/values/values.kt | 19 +++++++++++++++- .../tests/framework/values/values.swift | 11 ++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportNamer.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportNamer.kt index 5fcdd0af2cf..beefc5edd28 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportNamer.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportNamer.kt @@ -802,6 +802,10 @@ private fun ObjCExportMapper.canHaveSameName(first: PropertyDescriptor, second: return false } + if (first.name != second.name) { + return false + } + return bridgePropertyType(first) == bridgePropertyType(second) } diff --git a/backend.native/tests/framework/values/expectedLazy.h b/backend.native/tests/framework/values/expectedLazy.h index 29e9862e422..ae3d539c632 100644 --- a/backend.native/tests/framework/values/expectedLazy.h +++ b/backend.native/tests/framework/values/expectedLazy.h @@ -571,6 +571,28 @@ __attribute__((swift_name("TestSR10177Workaround"))) @required @end; +__attribute__((swift_name("TestClashes1"))) +@protocol ValuesTestClashes1 +@required +@property (readonly) int32_t clashingProperty __attribute__((swift_name("clashingProperty"))); +@end; + +__attribute__((swift_name("TestClashes2"))) +@protocol ValuesTestClashes2 +@required +@property (readonly) id clashingProperty __attribute__((swift_name("clashingProperty"))); +@property (readonly) id clashingProperty_ __attribute__((swift_name("clashingProperty_"))); +@end; + +__attribute__((objc_subclassing_restricted)) +__attribute__((swift_name("TestClashesImpl"))) +@interface ValuesTestClashesImpl : KotlinBase +- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); ++ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); +@property (readonly) int32_t clashingProperty __attribute__((swift_name("clashingProperty"))); +@property (readonly) ValuesInt *clashingProperty_ __attribute__((swift_name("clashingProperty_"))); +@end; + @interface ValuesEnumeration (ValuesKt) - (ValuesEnumeration *)getAnswer __attribute__((swift_name("getAnswer()"))); @end; diff --git a/backend.native/tests/framework/values/values.kt b/backend.native/tests/framework/values/values.kt index 926c9294478..27634a5aa0d 100644 --- a/backend.native/tests/framework/values/values.kt +++ b/backend.native/tests/framework/values/values.kt @@ -450,4 +450,21 @@ abstract class ForwardC1 { abstract fun getForwardC2(): ForwardC2 } -interface TestSR10177Workaround \ No newline at end of file +interface TestSR10177Workaround + +interface TestClashes1 { + val clashingProperty: Int +} + +interface TestClashes2 { + val clashingProperty: Any + val clashingProperty_: Any +} + +class TestClashesImpl : TestClashes1, TestClashes2 { + override val clashingProperty: Int + get() = 1 + + override val clashingProperty_: Int + get() = 2 +} diff --git a/backend.native/tests/framework/values/values.swift b/backend.native/tests/framework/values/values.swift index 11223bf0460..a945a1939cd 100644 --- a/backend.native/tests/framework/values/values.swift +++ b/backend.native/tests/framework/values/values.swift @@ -613,6 +613,16 @@ func testSR10177Workaround() throws { try assertTrue(String(describing: test).contains("TestSR10177WorkaroundDerived")) } +func testClashes() throws { + let test = TestClashesImpl() + let test1: TestClashes1 = test + let test2: TestClashes2 = test + + try assertEquals(actual: 1, expected: test1.clashingProperty) + try assertEquals(actual: 1, expected: test2.clashingProperty_ as! Int32) + try assertEquals(actual: 2, expected: test2.clashingProperty__ as! Int32) +} + // See https://github.com/JetBrains/kotlin-native/issues/2931 func testGH2931() throws { for i in 0..<50000 { @@ -678,6 +688,7 @@ class ValuesTests : TestProvider { TestCase(name: "TestGH2959", method: withAutorelease(testGH2959)), TestCase(name: "TestKClass", method: withAutorelease(testKClass)), TestCase(name: "TestSR10177Workaround", method: withAutorelease(testSR10177Workaround)), + TestCase(name: "TestClashes", method: withAutorelease(testClashes)), TestCase(name: "TestGH2931", method: withAutorelease(testGH2931)), ] }