From ccfcea85ec31f6bccbdab6d4cb504f45c81b96aa Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Mon, 10 Sep 2018 13:09:10 +0300 Subject: [PATCH] Minor: get MAX_VALUE directly from unsigned types --- .../resolve/constants/IntegerValueTypeConstructor.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueTypeConstructor.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueTypeConstructor.kt index cdfd0c76945..e028373bbcf 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueTypeConstructor.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/IntegerValueTypeConstructor.kt @@ -110,21 +110,18 @@ private fun KotlinType.minValue(): Long { } } +@ExperimentalUnsignedTypes private fun KotlinType.maxValue(): Long { return when { KotlinBuiltIns.isByte(this) -> Byte.MAX_VALUE.toLong() KotlinBuiltIns.isShort(this) -> Short.MAX_VALUE.toLong() KotlinBuiltIns.isInt(this) -> Int.MAX_VALUE.toLong() - KotlinBuiltIns.isUByte(this) -> UBYTE_MAX_VALUE - KotlinBuiltIns.isUShort(this) -> USHORT_MAX_VALUE - KotlinBuiltIns.isUInt(this) -> UINT_MAX_VALUE + KotlinBuiltIns.isUByte(this) -> UByte.MAX_VALUE.toLong() + KotlinBuiltIns.isUShort(this) -> UShort.MAX_VALUE.toLong() + KotlinBuiltIns.isUInt(this) -> UInt.MAX_VALUE.toLong() else -> error("Can't get max value for type: $this") } } -private val UBYTE_MAX_VALUE = (-1).toByte().fromUByteToLong() -private val USHORT_MAX_VALUE = (-1).toShort().fromUShortToLong() -private val UINT_MAX_VALUE = (-1).fromUIntToLong() -