[K2/N][Tests] Add test to demonstrate compiler behavior for ObjC properties intersection overrides
^KT-57640
diff --git a/compiler/testData/codegen/box/cinterop/kt57640.kt b/compiler/testData/codegen/box/cinterop/kt57640.kt
new file mode 100644
index 0000000..7b5cb8f
--- /dev/null
+++ b/compiler/testData/codegen/box/cinterop/kt57640.kt
@@ -0,0 +1,91 @@
+// TARGET_BACKEND: NATIVE
+// MODULE: cinterop
+// FILE: kt57640.def
+language = Objective-C
+headers = kt57640.h
+
+// FILE:
+#import <Foundation/NSObject.h>
+
+@interface Base : NSObject
+@property (readwrite) Base* delegate;
+@end
+
+@protocol Foo
+@property (readwrite) id<Foo> delegate;
+@end
+
+@protocol Bar
+@property (readwrite) id<Bar> delegate;
+@end
+
+@interface Derived : Base<Bar, Foo>
+// This interface does not have re-declaration of property `delegate`.
+// Return type of getter `delegate()` and param type of setter `setDelegate()` are:
+// the type of property defined in the first mentioned protocol (id<Bar>), which is incompatible with property type.
+@end
+
+@interface DerivedWithPropertyOverride : Base<Bar, Foo>
+// This interface does not have re-declaration of property `delegate`.
+// Return type of getter `delegate()` and param type of setter `setDelegate()` are `DerivedWithPropertyOverride*`
+@property (readwrite) DerivedWithPropertyOverride* delegate;
+@end
+
+// FILE: kt57640.m
+#import "kt57640.h"
+
+@implementation Base
+@end
+
+@implementation Derived
+@end
+
+@implementation DerivedWithPropertyOverride
+@end
+
+// MODULE: main(cinterop)
+// FILE: main.kt
+@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
+import kt57640.*
+import kotlin.test.*
+
+class GrandDerived: Derived() {}
+class GrandDerivedWithPropertyOverride: DerivedWithPropertyOverride() {}
+
+/**
+ * class KotlinInterfaceDerived would cause errors, this deserves a diagnostic test
+ * error: class 'KotlinInterfaceDerived' must override 'delegate' because it inherits multiple implementations for it.
+ * error: 'delegate' clashes with 'delegate': return types are incompatible.
+ * error: 'delegate' clashes with 'delegate': property types do not match.
+ */
+//class KotlinInterfaceDerived: Base(), FooProtocol, BarProtocol
+
+fun main() {
+ testBase()
+
+ testAssignmentDerivedToDerived()
+ testAssignmentDerivedToBase()
+ testAssignmentBaseToDerived()
+
+ testAssignmentDerivedWithPropertyOverrideToDerivedWithPropertyOverride()
+ testAssignmentDerivedWithPropertyOverrideToBase()
+ testAssignmentBaseToDerivedWithPropertyOverride()
+
+ testGrandDerived()
+ testGrandDerivedWithPropertyOverride()
+ testAssigmmentDerivedWithPropertyOverrideToGrandDerivedWithPropertyOverride()
+}
+
+private fun testBase() {
+ val base = Base()
+ val delegate00_Base: Base? = base.delegate
+ assertEquals(null, delegate00_Base)
+ val delegate01_Base: Base? = base.delegate()
+ assertEquals(null, delegate01_Base)
+
+ base.delegate = base
+ val delegate02_Base: Base? = base.delegate
+ assertEquals(base, delegate02_Base)
+ val delegate03_Base: Base? = base.delegate()
+ assertEquals(base, delegate03_Base)
+}
diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java
index 4322fc8..c83ad61 100644
--- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java
+++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestGenerated.java
@@ -4827,6 +4827,12 @@
}
@Test
+ @TestMetadata("kt57640.kt")
+ public void testKt57640() throws Exception {
+ runTest("compiler/testData/codegen/box/cinterop/kt57640.kt");
+ }
+
+ @Test
@TestMetadata("kt63048.kt")
public void testKt63048() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/kt63048.kt");
diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java
index ceab871..1b27e41 100644
--- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java
+++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/FirNativeCodegenBoxTestNoPLGenerated.java
@@ -4937,6 +4937,12 @@
}
@Test
+ @TestMetadata("kt57640.kt")
+ public void testKt57640() throws Exception {
+ runTest("compiler/testData/codegen/box/cinterop/kt57640.kt");
+ }
+
+ @Test
@TestMetadata("kt63048.kt")
public void testKt63048() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/kt63048.kt");
diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java
index f76f9cf..671ebbb 100644
--- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java
+++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestGenerated.java
@@ -4717,6 +4717,12 @@
}
@Test
+ @TestMetadata("kt57640.kt")
+ public void testKt57640() throws Exception {
+ runTest("compiler/testData/codegen/box/cinterop/kt57640.kt");
+ }
+
+ @Test
@TestMetadata("kt63048.kt")
public void testKt63048() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/kt63048.kt");
diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java
index 3ff9b8e..a1a10f1 100644
--- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java
+++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/blackbox/NativeCodegenBoxTestNoPLGenerated.java
@@ -4828,6 +4828,12 @@
}
@Test
+ @TestMetadata("kt57640.kt")
+ public void testKt57640() throws Exception {
+ runTest("compiler/testData/codegen/box/cinterop/kt57640.kt");
+ }
+
+ @Test
@TestMetadata("kt63048.kt")
public void testKt63048() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/kt63048.kt");