KT-313 Bug in substitutions in a function returning its type parameter T

This commit is contained in:
Andrey Breslav
2011-11-12 20:29:38 +04:00
parent 8d8145c3d2
commit c74a0a62cc
12 changed files with 36 additions and 20 deletions
@@ -18,8 +18,8 @@ fun foo(c: Consumer<Int>, p: Producer<Int>, u: Usual<Int>) {
}
//Arrays copy example
class Array<T>(val length : Int) {
fun get(index : Int) : T { return null }
class Array<T>(val length : Int, val t : T) {
fun get(index : Int) : T { return t }
fun set(index : Int, value : T) { /* ... */ }
}
@@ -0,0 +1,11 @@
// KT-313 Bug in substitutions in a function returning its type parameter T
fun <T> Iterable<T>.join(separator : String?) : String {
return separator.npe()
}
fun <T : Any> T?.npe() : T {
if (this == null)
throw NullPointerException()
return this;
}
@@ -1,7 +1,7 @@
namespace test
class List<T>(len: Int) {
val a : Array<T> = Array<T>(len)
val a : Array<T?> = Array<T?>(len)
fun reverse() {
var i = 0
@@ -29,7 +29,7 @@ fun box() : String {
val c = List<Array<Int>>(1)
c.a[0] = Array<Int>(4,{-1})
println(c.a[0].size)
println(c.a[0]?.size)
val e = List<Int>(5)
e.a[0] = 0
+3 -3
View File
@@ -36,8 +36,8 @@ trait WriteOnlyArray<in T> : ISized {
}
}
class MutableArray<T>(length: Int) : ReadOnlyArray<T>, WriteOnlyArray<T> {
private val array = Array<T>(length)
class MutableArray<T>(length: Int, init : fun(Int) : T) : ReadOnlyArray<T>, WriteOnlyArray<T> {
private val array = Array<T>(length, init)
override fun get(index : Int) : T = array[index]
override fun set(index : Int, value : T) : Unit { array[index] = value }
@@ -47,7 +47,7 @@ class MutableArray<T>(length: Int) : ReadOnlyArray<T>, WriteOnlyArray<T> {
}
fun box() : String {
var a = MutableArray<Int> (4)
var a = MutableArray<Int> (4, {0})
a [0] = 10
a.set(1, 2, 13)
a [3] = 40