From a7bf415ad53e0006d23241fe48974ebd9885a932 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 7 Jul 2015 05:07:40 +0300 Subject: [PATCH] plus: do not generate ambiguos overloads. --- libraries/stdlib/src/generated/_Generators.kt | 24 ++++++-------- .../src/templates/Generators.kt | 31 +++++++------------ 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/libraries/stdlib/src/generated/_Generators.kt b/libraries/stdlib/src/generated/_Generators.kt index 5fc48ae7361..8f5ebf60411 100644 --- a/libraries/stdlib/src/generated/_Generators.kt +++ b/libraries/stdlib/src/generated/_Generators.kt @@ -635,24 +635,20 @@ public fun Set.plus(array: Array): Set { return result } -/** - * Returns a list containing all elements of the original collection and then all elements of the given [collection]. - */ -public fun Collection.plus(collection: Collection): List { - val result = ArrayList(this.size() + collection.size()) - result.addAll(this) - result.addAll(collection) - return result -} - /** * Returns a list containing all elements of the original collection and then all elements of the given [collection]. */ public fun Collection.plus(collection: Iterable): List { - if (collection is Collection) return this.plus(collection) - val result = ArrayList(this) - result.addAll(collection) - return result + if (collection is Collection) { + val result = ArrayList(this.size() + collection.size()) + result.addAll(this) + result.addAll(collection) + return result + } else { + val result = ArrayList(this) + result.addAll(collection) + return result + } } /** diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt index a2606c501c3..286ffe4958b 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt @@ -52,7 +52,7 @@ fun generators(): List { only(Iterables, Collections, Sets, Sequences) doc { "Returns a list containing all elements of the original collection and then all elements of the given [collection]." } returns("List") - returns("SELF", ArraysOfObjects, ArraysOfPrimitives, Sets, Sequences) + returns("SELF", Sets, Sequences) body { """ if (this is Collection) return this.plus(collection) @@ -64,14 +64,19 @@ fun generators(): List { } body(Collections) { """ - if (collection is Collection) return this.plus(collection) - val result = ArrayList(this) - result.addAll(collection) - return result + if (collection is Collection) { + val result = ArrayList(this.size() + collection.size()) + result.addAll(this) + result.addAll(collection) + return result + } else { + val result = ArrayList(this) + result.addAll(collection) + return result + } """ } - // TODO: try to precalculate size // TODO: use immutable set builder when available doc(Sets) { "Returns a set containing all elements both of the original set and the given [collection]." } body(Sets) { @@ -91,20 +96,6 @@ fun generators(): List { } } - templates add f("plus(collection: Collection)") { - only(Collections) - doc { "Returns a list containing all elements of the original collection and then all elements of the given [collection]." } - returns("List") - body { - """ - val result = ArrayList(this.size() + collection.size()) - result.addAll(this) - result.addAll(collection) - return result - """ - } - } - templates add f("plus(array: Array)") { only(Iterables, Collections, Sets, Sequences) doc { "Returns a list containing all elements of the original collection and then all elements of the given [array]." }