From f7b2eba680c83f3f390c6d0f9faf49b03f709bd2 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Thu, 25 Jan 2018 19:05:36 +0300 Subject: [PATCH] Do not mix expect/non-expect overloads of minOf/maxOf Workaround for KT-22520 --- .../common/src/generated/_Comparisons.kt | 24 +++------ .../stdlib/js/src/generated/_ComparisonsJs.kt | 52 +++++++++++++++++++ .../jvm/src/generated/_ComparisonsJvm.kt | 52 +++++++++++++++++++ .../src/templates/Comparables.kt | 4 ++ 4 files changed, 114 insertions(+), 18 deletions(-) diff --git a/libraries/stdlib/common/src/generated/_Comparisons.kt b/libraries/stdlib/common/src/generated/_Comparisons.kt index e224f591a86..de68cee4a85 100644 --- a/libraries/stdlib/common/src/generated/_Comparisons.kt +++ b/libraries/stdlib/common/src/generated/_Comparisons.kt @@ -17,9 +17,7 @@ import kotlin.comparisons.* * If values are equal, returns the first one. */ @SinceKotlin("1.1") -public fun > maxOf(a: T, b: T): T { - return if (a >= b) a else b -} +public expect fun > maxOf(a: T, b: T): T /** * Returns the greater of two values. @@ -67,9 +65,7 @@ public expect inline fun maxOf(a: Double, b: Double): Double * Returns the greater of three values. */ @SinceKotlin("1.1") -public fun > maxOf(a: T, b: T, c: T): T { - return maxOf(a, maxOf(b, c)) -} +public expect fun > maxOf(a: T, b: T, c: T): T /** * Returns the greater of three values. @@ -97,9 +93,7 @@ public expect inline fun maxOf(a: Int, b: Int, c: Int): Int */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline fun maxOf(a: Long, b: Long, c: Long): Long { - return maxOf(a, maxOf(b, c)) -} +public expect inline fun maxOf(a: Long, b: Long, c: Long): Long /** * Returns the greater of three values. @@ -137,9 +131,7 @@ public fun maxOf(a: T, b: T, comparator: Comparator): T { * If values are equal, returns the first one. */ @SinceKotlin("1.1") -public fun > minOf(a: T, b: T): T { - return if (a <= b) a else b -} +public expect fun > minOf(a: T, b: T): T /** * Returns the smaller of two values. @@ -187,9 +179,7 @@ public expect inline fun minOf(a: Double, b: Double): Double * Returns the smaller of three values. */ @SinceKotlin("1.1") -public fun > minOf(a: T, b: T, c: T): T { - return minOf(a, minOf(b, c)) -} +public expect fun > minOf(a: T, b: T, c: T): T /** * Returns the smaller of three values. @@ -217,9 +207,7 @@ public expect inline fun minOf(a: Int, b: Int, c: Int): Int */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline fun minOf(a: Long, b: Long, c: Long): Long { - return minOf(a, minOf(b, c)) -} +public expect inline fun minOf(a: Long, b: Long, c: Long): Long /** * Returns the smaller of three values. diff --git a/libraries/stdlib/js/src/generated/_ComparisonsJs.kt b/libraries/stdlib/js/src/generated/_ComparisonsJs.kt index 559c9c02a7b..ca49c474a66 100644 --- a/libraries/stdlib/js/src/generated/_ComparisonsJs.kt +++ b/libraries/stdlib/js/src/generated/_ComparisonsJs.kt @@ -13,6 +13,15 @@ import kotlin.* import kotlin.text.* import kotlin.comparisons.* +/** + * Returns the greater of two values. + * If values are equal, returns the first one. + */ +@SinceKotlin("1.1") +public actual fun > maxOf(a: T, b: T): T { + return if (a >= b) a else b +} + /** * Returns the greater of two values. */ @@ -67,6 +76,14 @@ public actual inline fun maxOf(a: Double, b: Double): Double { return Math.max(a, b) } +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +public actual fun > maxOf(a: T, b: T, c: T): T { + return maxOf(a, maxOf(b, c)) +} + /** * Returns the greater of three values. */ @@ -94,6 +111,15 @@ public actual inline fun maxOf(a: Int, b: Int, c: Int): Int { return Math.max(a, b, c) } +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public actual inline fun maxOf(a: Long, b: Long, c: Long): Long { + return maxOf(a, maxOf(b, c)) +} + /** * Returns the greater of three values. */ @@ -112,6 +138,15 @@ public actual inline fun maxOf(a: Double, b: Double, c: Double): Double { return Math.max(a, b, c) } +/** + * Returns the smaller of two values. + * If values are equal, returns the first one. + */ +@SinceKotlin("1.1") +public actual fun > minOf(a: T, b: T): T { + return if (a <= b) a else b +} + /** * Returns the smaller of two values. */ @@ -166,6 +201,14 @@ public actual inline fun minOf(a: Double, b: Double): Double { return Math.min(a, b) } +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +public actual fun > minOf(a: T, b: T, c: T): T { + return minOf(a, minOf(b, c)) +} + /** * Returns the smaller of three values. */ @@ -193,6 +236,15 @@ public actual inline fun minOf(a: Int, b: Int, c: Int): Int { return Math.min(a, b, c) } +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public actual inline fun minOf(a: Long, b: Long, c: Long): Long { + return minOf(a, minOf(b, c)) +} + /** * Returns the smaller of three values. */ diff --git a/libraries/stdlib/jvm/src/generated/_ComparisonsJvm.kt b/libraries/stdlib/jvm/src/generated/_ComparisonsJvm.kt index 73017b7ef8f..ebf7801e9bc 100644 --- a/libraries/stdlib/jvm/src/generated/_ComparisonsJvm.kt +++ b/libraries/stdlib/jvm/src/generated/_ComparisonsJvm.kt @@ -13,6 +13,15 @@ import kotlin.* import kotlin.text.* import kotlin.comparisons.* +/** + * Returns the greater of two values. + * If values are equal, returns the first one. + */ +@SinceKotlin("1.1") +public actual fun > maxOf(a: T, b: T): T { + return if (a >= b) a else b +} + /** * Returns the greater of two values. */ @@ -67,6 +76,14 @@ public actual inline fun maxOf(a: Double, b: Double): Double { return Math.max(a, b) } +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +public actual fun > maxOf(a: T, b: T, c: T): T { + return maxOf(a, maxOf(b, c)) +} + /** * Returns the greater of three values. */ @@ -94,6 +111,15 @@ public actual inline fun maxOf(a: Int, b: Int, c: Int): Int { return maxOf(a, maxOf(b, c)) } +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public actual inline fun maxOf(a: Long, b: Long, c: Long): Long { + return maxOf(a, maxOf(b, c)) +} + /** * Returns the greater of three values. */ @@ -112,6 +138,15 @@ public actual inline fun maxOf(a: Double, b: Double, c: Double): Double { return maxOf(a, maxOf(b, c)) } +/** + * Returns the smaller of two values. + * If values are equal, returns the first one. + */ +@SinceKotlin("1.1") +public actual fun > minOf(a: T, b: T): T { + return if (a <= b) a else b +} + /** * Returns the smaller of two values. */ @@ -166,6 +201,14 @@ public actual inline fun minOf(a: Double, b: Double): Double { return Math.min(a, b) } +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +public actual fun > minOf(a: T, b: T, c: T): T { + return minOf(a, minOf(b, c)) +} + /** * Returns the smaller of three values. */ @@ -193,6 +236,15 @@ public actual inline fun minOf(a: Int, b: Int, c: Int): Int { return minOf(a, minOf(b, c)) } +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public actual inline fun minOf(a: Long, b: Long, c: Long): Long { + return minOf(a, minOf(b, c)) +} + /** * Returns the smaller of three values. */ diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt index 1681251390d..3d73375fc2a 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt @@ -179,6 +179,7 @@ object ComparableOps : TemplateGroupBase() { } } } + on(Platform.JS) { /* just to make expect, KT-22520 */ } body(Generic) { "return if (a <= b) a else b" } @@ -203,6 +204,7 @@ object ComparableOps : TemplateGroupBase() { body { "return minOf(a, minOf(b, c))" } + on(Platform.JS) { /* just to make expect, KT-22520 */ } specialFor(Primitives) { if (primitive in shortIntPrimitives) { body { "return Math.min(a.toInt(), Math.min(b.toInt(), c.toInt())).to$primitive()" } @@ -291,6 +293,7 @@ object ComparableOps : TemplateGroupBase() { } } } + on(Platform.JS) { /* just to make expect, KT-22520 */ } body(Generic) { "return if (a >= b) a else b" } @@ -315,6 +318,7 @@ object ComparableOps : TemplateGroupBase() { body { "return maxOf(a, maxOf(b, c))" } + on(Platform.JS) { /* just to make expect, KT-22520 */ } specialFor(Primitives) { if (primitive in shortIntPrimitives) { body { "return Math.max(a.toInt(), Math.max(b.toInt(), c.toInt())).to$primitive()" }