From 99d995a313f38d7566cb04fd85e8b5c336895b3b Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Wed, 20 Apr 2022 13:42:45 +0200 Subject: [PATCH] [Commonizer] Implement integration test for KT-52050 The test project will be compiled and proves that 'platform.posix.DIR' retains it's 'CPointed' supertype. The test is expected to fail on platforms that do not support macos (windows and linux), since the issue seems to be caused by optimistic, single platform propagation. --- .../kotlin/gradle/CommonizerHierarchicalIT.kt | 10 ++++++++ .../build.gradle.kts | 24 +++++++++++++++++++ .../src/commonMain/kotlin/CommonMain.kt | 17 +++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-52050-DIR-supertype/build.gradle.kts create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-52050-DIR-supertype/src/commonMain/kotlin/CommonMain.kt diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/CommonizerHierarchicalIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/CommonizerHierarchicalIT.kt index 736c307e276..da11b6ecdf7 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/CommonizerHierarchicalIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/CommonizerHierarchicalIT.kt @@ -153,6 +153,16 @@ class CommonizerHierarchicalIT : BaseGradleIT() { } } + @Test + fun `test KT-52050 - DIR retains CPointed supertype`() { + with(Project("commonize-kt-52050-DIR-supertype")) { + build(":compileCommonMainKotlinMetadata") { + assertNotContains("Unresolved reference") + assertSuccessful() + } + } + } + private object Os { private val os = OperatingSystem.current() val canCompileApple get() = os.isMacOsX diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-52050-DIR-supertype/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-52050-DIR-supertype/build.gradle.kts new file mode 100644 index 00000000000..a3a543c9d8b --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-52050-DIR-supertype/build.gradle.kts @@ -0,0 +1,24 @@ +plugins { + kotlin("multiplatform") +} + +repositories { + mavenLocal() + mavenCentral() +} + +kotlin { + macosX64("macos") + linuxX64("linux") + mingwX64("windows") + + val commonMain by sourceSets.getting + val macosMain by sourceSets.getting + val linuxMain by sourceSets.getting + + val unixMain by sourceSets.creating + + unixMain.dependsOn(commonMain) + linuxMain.dependsOn(unixMain) + macosMain.dependsOn(unixMain) +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-52050-DIR-supertype/src/commonMain/kotlin/CommonMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-52050-DIR-supertype/src/commonMain/kotlin/CommonMain.kt new file mode 100644 index 00000000000..56084734fc2 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/commonize-kt-52050-DIR-supertype/src/commonMain/kotlin/CommonMain.kt @@ -0,0 +1,17 @@ +@file:Suppress("UNUSED_PARAMETER") + +import kotlinx.cinterop.CPointed +import platform.posix.DIR + +fun requireCPointed(value: CPointed): Unit = error("Not supported") +fun DIR(): DIR = error("Not supported") + +fun main() { + /* + Linux and Windows Hosts failed to retain + CPointed supertype of `DIR` when commonizing. + This happened in the special case of 'single platform propagation', which + lost forward declarations from one step to the next. + */ + requireCPointed(DIR()) +}