diff --git a/native/commonizer/src/org/jetbrains/kotlin/commonizer/core/ClassOrTypeAliasTypeCommonizer.kt b/native/commonizer/src/org/jetbrains/kotlin/commonizer/core/ClassOrTypeAliasTypeCommonizer.kt index a485402459c..f9563f81a71 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/commonizer/core/ClassOrTypeAliasTypeCommonizer.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/commonizer/core/ClassOrTypeAliasTypeCommonizer.kt @@ -232,8 +232,14 @@ private fun resolveTypeSubstitutionCandidates( if (typeDistances.any { it.isNotReachable }) return@mapCandidateId null TypeSubstitutionCandidate( id = candidateId, - // TODO NOW: Any negative should outperform any positive substitution!, so negative will be chosen here as 'worst' - typeDistance = checkNotNull(typeDistances.maxByOrNull { distance -> distance.absoluteValue }) + typeDistance = checkNotNull(typeDistances.worstOrNull()) ) } } + +private fun List.worstOrNull(): CirTypeDistance? { + if (this.isEmpty()) return null + // Negative Type Distances are considered 'worse' + filter { it.isNegative }.minOrNull()?.let { return it } + return maxOrNull() +} \ No newline at end of file