diff --git a/native/commonizer/src/org/jetbrains/kotlin/commonizer/core/PlatformIntegerCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/commonizer/core/PlatformIntegerCommonizer.kt index 182e99d6c52..650fb872e4d 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/commonizer/core/PlatformIntegerCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/commonizer/core/PlatformIntegerCommonizer.kt @@ -62,8 +62,8 @@ private sealed class PlatformDependentTypeCommonizer( private fun inputTypeIsKnownAndMatchesPlatformBitWidth(type: CirClassOrTypeAliasType, target: CommonizerTarget): Boolean = when (PlatformWidthIndex.platformWidthOf(target)) { - PlatformIntWidth.INT -> type.classifierId == intPlatformId - PlatformIntWidth.LONG -> type.classifierId == longPlatformId + PlatformIntWidth.INT -> type.classifierId == intPlatformId || type.classifierId == mixedPlatformId + PlatformIntWidth.LONG -> type.classifierId == longPlatformId || type.classifierId == mixedPlatformId PlatformIntWidth.MIXED -> type.classifierId == mixedPlatformId null -> false } diff --git a/native/commonizer/tests/org/jetbrains/kotlin/commonizer/hierarchical/HierarchicalPlatformIntegerCommonizationTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/commonizer/hierarchical/HierarchicalPlatformIntegerCommonizationTest.kt index de8dcfdd92c..fb8c159ab5f 100644 --- a/native/commonizer/tests/org/jetbrains/kotlin/commonizer/hierarchical/HierarchicalPlatformIntegerCommonizationTest.kt +++ b/native/commonizer/tests/org/jetbrains/kotlin/commonizer/hierarchical/HierarchicalPlatformIntegerCommonizationTest.kt @@ -616,4 +616,59 @@ class HierarchicalPlatformIntegerCommonizationTest : AbstractInlineSourcesCommon """.trimIndent() ) } + + fun `test platform types from known leaf targets are commonized`() { + val result = commonize { + outputTarget("(${LINUX_X64.name}, ${IOS_ARM32.name})") + setting(PlatformIntegerCommonizationEnabledKey, true) + registerFakeStdlibIntegersDependency("(${LINUX_X64.name}, ${IOS_ARM32.name})") + + LINUX_X64.name withSource """ + val platformPropertyInOneLeafTarget: PlatformInt + get() = null!! + val platformPropertyInBothLeafTargets: PlatformInt + get() = null!! + """.trimIndent() + + IOS_ARM32.name withSource """ + val platformPropertyInOneLeafTarget: Int + get() = 42 + val platformPropertyInBothLeafTargets: PlatformInt + get() = null!! + """.trimIndent() + } + + result.assertCommonized( + "(${LINUX_X64.name}, ${IOS_ARM32.name})", """ + expect val platformPropertyInOneLeafTarget: PlatformInt + expect val platformPropertyInBothLeafTargets: PlatformInt + """.trimIndent() + ) + } + + fun `test platform types from unknown targets are not commonized`() { + val result = commonize { + outputTarget("(unknown, ${IOS_ARM32.name})") + setting(PlatformIntegerCommonizationEnabledKey, true) + registerFakeStdlibIntegersDependency("(unknown, ${IOS_ARM32.name})") + + "unknown" withSource """ + val platformPropertyInOneLeafTarget: PlatformInt + get() = null!! + val platformPropertyInOtherLeafTarget: Int + get() = null!! + """.trimIndent() + + IOS_ARM32.name withSource """ + val platformPropertyInOneLeafTarget: Int + get() = 42 + val platformPropertyInOtherLeafTarget: PlatformInt + get() = null!! + """.trimIndent() + } + + result.assertCommonized( + "(unknown, ${IOS_ARM32.name})", "".trimIndent() + ) + } }