Fix Array<out> variance in stdlib #KT-6482 Fixed

This commit is contained in:
Ilya Ryzhenkov
2014-12-22 23:08:41 +03:00
parent 377988cb7b
commit 4cd2ba1e30
11 changed files with 66 additions and 61 deletions
@@ -39,8 +39,8 @@ class GenericFunction(val signature: String) : Comparable<GenericFunction> {
var receiverAsterisk = false
val inlineFamilies = HashMap<Family, Boolean>()
val buildFamilies = HashSet<Family>(defaultFamilies.toList())
private val buildPrimitives = HashSet<PrimitiveType>(PrimitiveType.values().toList())
val buildFamilies = HashSet(defaultFamilies.toList())
private val buildPrimitives = HashSet(PrimitiveType.values().toList())
var deprecate: String = ""
val deprecates = HashMap<Family, String>()
@@ -106,7 +106,7 @@ class GenericFunction(val signature: String) : Comparable<GenericFunction> {
}
fun receiverAsterisk(v: Boolean) {
receiverAsterisk = true
receiverAsterisk = v
}
fun inline(value: Boolean, vararg families: Family) {
@@ -183,7 +183,7 @@ class GenericFunction(val signature: String) : Comparable<GenericFunction> {
while (t.hasMoreTokens()) {
val token = t.nextToken()
answer.append(when (token) {
"SELF" -> receiver
"SELF" -> if (receiver == "Array<T>") "Array<out T>" else receiver
"PRIMITIVE" -> primitive?.name() ?: token
"SUM" -> {
when (primitive) {
@@ -257,17 +257,12 @@ class GenericFunction(val signature: String) : Comparable<GenericFunction> {
val types = effectiveTypeParams()
if (!types.isEmpty()) {
builder.append(types.makeString(separator = ", ", prefix = "<", postfix = "> ").renderType())
builder.append(types.join(separator = ", ", prefix = "<", postfix = "> ").renderType())
}
val receiverType = (
if (toNullableT) {
receiver.replace("T>", "T?>")
} else {
if (receiver == "Array<T>")
"Array<out T>"
else
receiver
val receiverType = (when (receiver) {
"Array<T>" -> if (toNullableT) "Array<out T?>" else "Array<out T>"
else -> if (toNullableT) receiver.replace("T>", "T?>") else receiver
}).renderType()
@@ -275,7 +270,7 @@ class GenericFunction(val signature: String) : Comparable<GenericFunction> {
builder.append(".${signature.renderType()}: ${returnType.renderType()} {")
val body = (bodies[f] ?: defaultBody).trim("\n")
val indent: Int = body.takeWhile { it == ' ' }.length
val indent: Int = body.takeWhile { it == ' ' }.length()
builder.append('\n')
StringReader(body).forEachLine {
@@ -39,7 +39,7 @@ fun generators(): List<GenericFunction> {
}
}
templates add f("plus(array: Array<T>)") {
templates add f("plus(array: Array<out T>)") {
exclude(Strings, Streams)
doc { "Returns a list containing all elements of original collection and then all elements of the given *collection*" }
returns("List<T>")
@@ -142,7 +142,7 @@ fun generators(): List<GenericFunction> {
}
}
templates add f("merge(array: Array<R>, transform: (T, R) -> V)") {
templates add f("merge(array: Array<out R>, transform: (T, R) -> V)") {
exclude(Streams)
doc {
"""
@@ -222,7 +222,7 @@ fun generators(): List<GenericFunction> {
}
}
templates add f("zip(array: Array<R>)") {
templates add f("zip(array: Array<out R>)") {
exclude(Streams)
doc {
"""
@@ -9,6 +9,7 @@ fun specialJVM(): List<GenericFunction> {
only(ArraysOfObjects, ArraysOfPrimitives)
doc { "Returns new array which is a copy of range of original array" }
returns("SELF")
returns(ArraysOfObjects) { "Array<T>" }
body {
"return Arrays.copyOfRange(this, from, to)"
}
@@ -18,6 +19,7 @@ fun specialJVM(): List<GenericFunction> {
only(ArraysOfObjects, ArraysOfPrimitives)
doc { "Returns new array which is a copy of the original array" }
returns("SELF")
returns(ArraysOfObjects) { "Array<T>" }
body {
"return Arrays.copyOf(this, size())"
}