[K/N] Make cinterop include unused Objective-C forward declarations

Previously, when an Objective-C library had an unused Objective-C
forward declaration (`@class` or `@protocol`), cinterop tool didn't
include it into the resulting klib at all.

This led to a subtle bug (KT-64105). One Obj-C library has unused
Obj-C forward declaration, and another one depends on the first and
uses this forward declaration, e.g. as a function result type.
When building the first cinterop klib, this forward declaration is not
added to `includedForwardDeclarations` in the klib manifest (the
compiler uses this property to decide whether to synthesize the
corresponding class).
When building the second cinterop klib, the forward declaration is not
added to its manifest either, because it is located in the dependency
(and therefore should've been included there).
As a result, the forward declaration is included nowhere, and any
attempt to use it in Kotlin fails, including calling the function from
the second lib.

This commit fixes this bug by including even unused Objective-C forward
declarations, which is consistent with any other kind of declarations
and seems more natural.

^KT-64105 Fixed
This commit is contained in:
Svyatoslav Scherbina
2024-01-16 18:23:46 +01:00
committed by Space Team
parent 59142b3051
commit 2e5a9b1416
25 changed files with 312 additions and 0 deletions
@@ -4874,6 +4874,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
runTest("compiler/testData/codegen/box/cinterop/kt63049.kt");
}
@Test
@TestMetadata("kt64105.kt")
public void testKt64105() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/kt64105.kt");
}
@Test
@TestMetadata("leakMemoryWithRunningThreadUnchecked.kt")
public void testLeakMemoryWithRunningThreadUnchecked() throws Exception {
@@ -4984,6 +4984,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
runTest("compiler/testData/codegen/box/cinterop/kt63049.kt");
}
@Test
@TestMetadata("kt64105.kt")
public void testKt64105() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/kt64105.kt");
}
@Test
@TestMetadata("leakMemoryWithRunningThreadUnchecked.kt")
public void testLeakMemoryWithRunningThreadUnchecked() throws Exception {
@@ -4764,6 +4764,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
runTest("compiler/testData/codegen/box/cinterop/kt63049.kt");
}
@Test
@TestMetadata("kt64105.kt")
public void testKt64105() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/kt64105.kt");
}
@Test
@TestMetadata("leakMemoryWithRunningThreadUnchecked.kt")
public void testLeakMemoryWithRunningThreadUnchecked() throws Exception {
@@ -4875,6 +4875,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
runTest("compiler/testData/codegen/box/cinterop/kt63049.kt");
}
@Test
@TestMetadata("kt64105.kt")
public void testKt64105() throws Exception {
runTest("compiler/testData/codegen/box/cinterop/kt64105.kt");
}
@Test
@TestMetadata("leakMemoryWithRunningThreadUnchecked.kt")
public void testLeakMemoryWithRunningThreadUnchecked() throws Exception {