tests for obsolete/fixed issues

#KT-1038 fixed
 #KT-1127 fixed
 #KT-1145 fixed
 #KT-1410 fixed
 #KT-1718 fixed
 #KT-2286 fixed
 #KT-1431 fixed
 #KT-2394 fixed
This commit is contained in:
Svetlana Isakova
2012-08-16 18:02:21 +04:00
parent fc858aec59
commit d2e33c8900
11 changed files with 245 additions and 9 deletions
@@ -9,6 +9,16 @@ fun foo() {
val u = v map { it * 2 }
u : List<Int>
val a = 1..5
val b = a.map { it * 2 }
b : List<Int>
//check for non-error types
<!TYPE_MISMATCH!>u<!> : String
<!TYPE_MISMATCH!>b<!> : String
}
@@ -17,12 +27,6 @@ fun foo() {
fun <T> array(vararg t : T) : Array<T> = t
fun <T, R> Array<T>.map(transform : (T) -> R) : java.util.List<R> {
return mapTo(java.util.ArrayList<R>(this.size), transform)
}
fun <T, R> Array<T>.map(<!UNUSED_PARAMETER!>transform<!> : (T) -> R) : java.util.List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T, R, C: Collection<in R>> Array<T>.mapTo(result: C, transform : (T) -> R) : C {
for (item in this)
result.add(transform(item))
return result
}
fun <T, R> Iterable<T>.map(<!UNUSED_PARAMETER!>transform<!> : (T) -> R) : java.util.List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -0,0 +1,11 @@
//KT-1127 Wrong type computed for Arrays.asList()
package d
import java.util.List
fun <T> asList(<!UNUSED_PARAMETER!>t<!>: T) : List<T>? {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun main(args : Array<String>) {
val <!UNUSED_VARIABLE!>list<!> : List<String> = <!TYPE_MISMATCH!>asList("")<!>
}
@@ -0,0 +1,13 @@
//KT-1145 removing explicit generics on a call to Iterable<T>.map(...) seems to generate an odd bytecode/runtime error
package d
fun test(numbers: Iterable<Int>) {
val s = numbers.map{it.toString()}.fold(""){(it, it2) -> it + it2}
<!TYPE_MISMATCH!>s<!>: Int
}
//from library
fun <T, R> Iterable<T>.map(<!UNUSED_PARAMETER!>transform<!> : (T) -> R) : java.util.List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T> Iterable<T>.fold(<!UNUSED_PARAMETER!>initial<!>: T, <!UNUSED_PARAMETER!>operation<!>: (T, T) -> T): T {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -0,0 +1,27 @@
// KT-1410 Compiler does automatically infer type argument when using variance
//+JDK
package d
import java.util.Collection
import java.util.List
public fun <T> Collection<out T>.filterToMy(result : List<in T>, filter : (T) -> Boolean) : Collection<out T> {
for (t in this){
if (filter(t)){
result.add(t)
}
}
return this
}
fun foo(result: List<in String>, val collection: Collection<String>, prefix : String){
collection.filterToMy(result, {it.startsWith(prefix)})
}
fun test(result: List<in Any>, val collection: Collection<String>, prefix : String){
val c = collection.filterToMy(result, {it.startsWith(prefix)})
c: Collection<out String>
}
//from library
fun String.startsWith(<!UNUSED_PARAMETER!>prefix<!>: String) : Boolean {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -0,0 +1,16 @@
//KT-1718 compiler error when not using temporary variable
package n
import java.util.List
import java.util.ArrayList
fun test() {
val list = arrayList("foo", "bar") + arrayList("cheese", "wine")
list: List<String>
//check it's not an error type
<!TYPE_MISMATCH!>list<!>: Int
}
//from library
fun arrayList<T>(vararg <!UNUSED_PARAMETER!>values<!>: T) : ArrayList<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <in T> Iterable<T>.plus(<!UNUSED_PARAMETER!>elements<!>: Iterable<T>): List<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -0,0 +1,27 @@
// KT-2286 Improve error message for nullability check failure for extension methods
package n
abstract class Buggy {
abstract val coll : java.util.Collection<Int>
fun getThree(): Int? {
return coll.find{ it > 3 } // works fine
}
val anotherThree : Int
get() = <!TYPE_MISMATCH!>coll.find{ it > 3 }<!> // does not work here
val yetAnotherThree : Int
get() = <!TYPE_MISMATCH!>coll.find({ (v:Int) -> v > 3 })<!> // neither here
val extendedGetter : Int
get() {
return <!TYPE_MISMATCH!>coll.find{ it > 3 }<!> // not even here!
}
}
//from library
fun <T> Iterable<T>.find(<!UNUSED_PARAMETER!>predicate<!>: (T) -> Boolean) : T? {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>