Return EMPTY range [0, -1] when MIN_VALUE is specified as exclusive upper bound.
#KT-12762 Fixed
This commit is contained in:
@@ -83,12 +83,15 @@ fun ranges(): List<GenericFunction> {
|
||||
val elementType = rangeElementType(fromType, toType)
|
||||
val progressionType = elementType.name + "Range"
|
||||
returns(progressionType)
|
||||
val minValue = if (elementType == PrimitiveType.Char) "'\\u0000'" else "$elementType.MIN_VALUE"
|
||||
|
||||
doc {
|
||||
"""
|
||||
Returns a range from this value up to but excluding the specified [to] value.
|
||||
|
||||
${ if (elementType == toType) "The [to] value must be greater than [$elementType.MIN_VALUE]." else "" }
|
||||
${textWhen(elementType == toType) {
|
||||
"If the [to] value is less than or equal to [$minValue] the returned range is empty."
|
||||
}}
|
||||
"""
|
||||
}
|
||||
|
||||
@@ -102,10 +105,10 @@ fun ranges(): List<GenericFunction> {
|
||||
else -> "to"
|
||||
}
|
||||
body {
|
||||
// <= instead of == for JS
|
||||
"""
|
||||
val to_ = ($toExpr - 1).to$elementType()
|
||||
if (to_ > to) throw IllegalArgumentException("The to argument value '${'$'}to' was too small.")
|
||||
return $fromExpr .. to_
|
||||
if (to <= $minValue) return $progressionType.EMPTY
|
||||
return $fromExpr .. (to - 1).to$elementType()
|
||||
"""
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -38,6 +38,8 @@ object DocExtensions {
|
||||
else -> "list"
|
||||
}
|
||||
|
||||
fun textWhen(condition: Boolean, text: () -> String): String = if (condition) text() else ""
|
||||
|
||||
private fun String.singularize() = removeSuffix("s")
|
||||
|
||||
public fun String.pluralize() = when {
|
||||
|
||||
Reference in New Issue
Block a user