Restore default parameter values in JS collection constructors

Even if they now have overloads that will be selected when these parameters are omitted.
This is to preserve compatibility with the libraries compiled against the older library.

#KT-24782 Fixed
This commit is contained in:
Ilya Gorbunov
2018-06-05 22:15:02 +03:00
parent c150878086
commit 0f972f2412
6 changed files with 13 additions and 8 deletions
@@ -23,7 +23,8 @@ public actual open class ArrayList<E> internal constructor(private var array: Ar
* Creates an empty [ArrayList].
* @param initialCapacity initial capacity (ignored)
*/
public actual constructor(initialCapacity: Int) : this(emptyArray()) {}
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual constructor(initialCapacity: Int = 0) : this(emptyArray()) {}
/**
* Creates an [ArrayList] filled from the [elements] collection.
@@ -66,10 +66,11 @@ public actual open class HashMap<K, V> : AbstractMutableMap<K, V>, MutableMap<K,
*
* @throws IllegalArgumentException if the initial capacity or load factor are negative
*/
actual constructor(initialCapacity: Int, loadFactor: Float) : this() {
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
actual constructor(initialCapacity: Int, loadFactor: Float = 0.0f) : this() {
// This implementation of HashMap has no need of load factors or capacities.
require(initialCapacity >= 0) { "Negative initial capacity" }
require(loadFactor >= 0) { "Non-positive load factor" }
require(initialCapacity >= 0) { "Negative initial capacity: $initialCapacity" }
require(loadFactor >= 0) { "Non-positive load factor: $loadFactor" }
}
actual constructor(initialCapacity: Int) : this(initialCapacity, 0.0f)
@@ -39,7 +39,8 @@ public actual open class HashSet<E> : AbstractMutableSet<E>, MutableSet<E> {
*
* @throws IllegalArgumentException if the initial capacity or load factor are negative
*/
actual constructor(initialCapacity: Int, loadFactor: Float) {
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
actual constructor(initialCapacity: Int, loadFactor: Float = 0.0f) {
map = HashMap<E, Any>(initialCapacity, loadFactor)
}
@@ -174,7 +174,8 @@ public actual open class LinkedHashMap<K, V> : HashMap<K, V>, MutableMap<K, V> {
*
* @throws IllegalArgumentException if the initial capacity or load factor are negative
*/
actual constructor(initialCapacity: Int, loadFactor: Float) : super(initialCapacity, loadFactor) {
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
actual constructor(initialCapacity: Int, loadFactor: Float = 0.0f) : super(initialCapacity, loadFactor) {
map = HashMap<K, ChainEntry<K, V>>()
}
@@ -38,7 +38,8 @@ public actual open class LinkedHashSet<E> : HashSet<E>, MutableSet<E> {
*
* @throws IllegalArgumentException if the initial capacity or load factor are negative
*/
actual constructor(initialCapacity: Int, loadFactor: Float) : super(LinkedHashMap<E, Any>(initialCapacity, loadFactor))
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
actual constructor(initialCapacity: Int, loadFactor: Float = 0.0f) : super(LinkedHashMap<E, Any>(initialCapacity, loadFactor))
actual constructor(initialCapacity: Int) : this(initialCapacity, 0.0f)
+1 -1
View File
@@ -12,7 +12,7 @@ public actual interface Appendable {
public actual fun append(c: Char): Appendable
}
public actual class StringBuilder(content: String) : Appendable, CharSequence {
public actual class StringBuilder(content: String = "") : Appendable, CharSequence {
actual constructor(capacity: Int) : this() {}
actual constructor(content: CharSequence) : this(content.toString()) {}