Refine the exception type of EmptyRange.random()
Make it the same type as in case of an empty collection, so that `emptyRange.random()` throws the same exception as `emptyRange.toList().random()`. #KT-15539
This commit is contained in:
@@ -877,7 +877,13 @@ object Elements : TemplateGroupBase() {
|
||||
PrimitiveType.Char -> "nextInt(first.toInt(), last.toInt() + 1).toChar()"
|
||||
else -> "next$primitive(this)"
|
||||
}
|
||||
"""return random.$expr"""
|
||||
"""
|
||||
try {
|
||||
return random.$expr
|
||||
} catch(e: IllegalArgumentException) {
|
||||
throw NoSuchElementException(e.message)
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user