From a6f1048e8a44905421f03934fd9e86bc9c3cb8df Mon Sep 17 00:00:00 2001 From: SvyatoslavScherbina Date: Fri, 19 Apr 2019 23:22:45 +0300 Subject: [PATCH] Fix #2872 (#2898) --- .../native/interop/gen/jvm/StubGenerator.kt | 2 ++ backend.native/tests/interop/objc/smoke.h | 18 +++++++++++++++++- backend.native/tests/interop/objc/smoke.kt | 16 ++++++++++++++++ backend.native/tests/interop/objc/smoke.m | 11 ++++++++++- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/StubGenerator.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/StubGenerator.kt index 1641eacc0b2..d5c65027b75 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/StubGenerator.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/StubGenerator.kt @@ -885,6 +885,8 @@ class StubGenerator( if (configuration.library.language == Language.OBJECTIVE_C) { add("CONFLICTING_OVERLOADS") add("RETURN_TYPE_MISMATCH_ON_INHERITANCE") + add("PROPERTY_TYPE_MISMATCH_ON_INHERITANCE") // Multiple-inheriting property with conflicting types + add("VAR_TYPE_MISMATCH_ON_INHERITANCE") // Multiple-inheriting mutable property with conflicting types add("RETURN_TYPE_MISMATCH_ON_OVERRIDE") add("WRONG_MODIFIER_CONTAINING_DECLARATION") // For `final val` in interface. add("PARAMETER_NAME_CHANGED_ON_OVERRIDE") diff --git a/backend.native/tests/interop/objc/smoke.h b/backend.native/tests/interop/objc/smoke.h index da1823e752f..31c0e4d20c1 100644 --- a/backend.native/tests/interop/objc/smoke.h +++ b/backend.native/tests/interop/objc/smoke.h @@ -159,4 +159,20 @@ NSObject* createNSObject() { @interface TestOverrideInit : NSObject -(instancetype)initWithValue:(int)value NS_DESIGNATED_INITIALIZER; +(instancetype)createWithValue:(int)value; -@end; \ No newline at end of file +@end; + +@interface MultipleInheritanceClashBase : NSObject +@property (nonnull) MultipleInheritanceClashBase* delegate; +@end; + +@protocol MultipleInheritanceClash +@optional +@property (nullable) id delegate; +@end; + +@interface MultipleInheritanceClash1 : MultipleInheritanceClashBase +@end; + +@interface MultipleInheritanceClash2 : MultipleInheritanceClashBase +@property MultipleInheritanceClashBase* delegate; +@end; diff --git a/backend.native/tests/interop/objc/smoke.kt b/backend.native/tests/interop/objc/smoke.kt index 931bbdb04fb..cb852f7d0e3 100644 --- a/backend.native/tests/interop/objc/smoke.kt +++ b/backend.native/tests/interop/objc/smoke.kt @@ -23,6 +23,7 @@ fun run() { testCustomRetain() testVarargs() testOverrideInit() + testMultipleInheritanceClash() assertEquals(2, ForwardDeclaredEnum.TWO.value) @@ -310,6 +311,21 @@ class TestOverrideInitImpl @OverrideInit constructor(val value: Int) : TestOverr private class MyException : Throwable() +fun testMultipleInheritanceClash() { + val clash1 = MultipleInheritanceClash1() + val clash2 = MultipleInheritanceClash2() + + clash1.delegate = clash1 + assertEquals(clash1, clash1.delegate) + clash1.setDelegate(clash2) + assertEquals(clash2, clash1.delegate()) + + clash2.delegate = clash1 + assertEquals(clash1, clash2.delegate) + clash2.setDelegate(clash2) + assertEquals(clash2, clash2.delegate()) +} + fun nsArrayOf(vararg elements: Any): NSArray = NSMutableArray().apply { elements.forEach { this.addObject(it as ObjCObject) diff --git a/backend.native/tests/interop/objc/smoke.m b/backend.native/tests/interop/objc/smoke.m index aa7f078deea..c557bc34837 100644 --- a/backend.native/tests/interop/objc/smoke.m +++ b/backend.native/tests/interop/objc/smoke.m @@ -154,4 +154,13 @@ static CustomRetainMethodsImpl* retainedCustomRetainMethodsImpl; +(instancetype)createWithValue:(int)value { return [[self alloc] initWithValue:value]; } -@end; \ No newline at end of file +@end; + +@implementation MultipleInheritanceClashBase +@end; + +@implementation MultipleInheritanceClash1 +@end; + +@implementation MultipleInheritanceClash2 +@end;