deprecating types after colon

This commit is contained in:
Dmitry Jemerov
2015-04-21 18:32:31 +02:00
parent b7a4b3c17d
commit f374eec8f1
268 changed files with 1055 additions and 769 deletions
@@ -1,3 +1,5 @@
// !CHECK_TYPE
//KT-1029 Wrong type inference
package i
@@ -11,5 +13,5 @@ fun a() {
val x = 0..200
val odd = from (x where {it%2==0}) // I believe it should infer here
odd : Iterable<Int>
checkSubtype<Iterable<Int>>(odd)
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
//KT-1031 Can't infer type of `it` with two lambdas
package i
@@ -14,6 +16,6 @@ fun a() {
val z = x where { i: Int -> i % 2 == 0 }
val yielder = select(x where { it%2==0 }, { it.toString() })
z : () -> Iterable<Int>
yielder : () -> Iterable<String>
checkSubtype<() -> Iterable<Int>>(z)
checkSubtype<() -> Iterable<String>>(yielder)
}
@@ -1,10 +1,12 @@
// !CHECK_TYPE
//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
checkSubtype<Int>(<!TYPE_MISMATCH!>s<!>)
}
//from library
@@ -1,3 +1,5 @@
// !CHECK_TYPE
// KT-1410 Compiler does automatically infer type argument when using variance
//+JDK
package d
@@ -17,7 +19,7 @@ fun foo(result: MutableList<in String>, collection: MutableCollection<String>, p
fun test(result: MutableList<in Any>, collection: MutableCollection<String>, prefix : String){
val c = collection.filterToMy(result, {it.startsWith(prefix)})
c: MutableCollection<out String>
checkSubtype<MutableCollection<out String>>(c)
}
//from library
@@ -1,3 +1,5 @@
// !CHECK_TYPE
//KT-1718 compiler error when not using temporary variable
package n
@@ -5,9 +7,9 @@ import java.util.ArrayList
fun test() {
val list = arrayList("foo", "bar") + arrayList("cheese", "wine")
list: List<String>
checkSubtype<List<String>>(list)
//check it's not an error type
<!TYPE_MISMATCH!>list<!>: Int
checkSubtype<Int>(<!TYPE_MISMATCH!>list<!>)
}
//from library
@@ -1,3 +1,5 @@
// !CHECK_TYPE
//KT-1944 Inference fails on run()
package j
@@ -7,7 +9,7 @@ class P {
fun foo() {
val r = run {x = 5} // ERROR
r : Unit
checkSubtype<Unit>(r)
}
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
//KT-2179 Nested function literal breaks compiler
package i
@@ -9,16 +11,16 @@ fun test() {
//breaks compiler
val sample2 = sample1.map({it.map({it})})
sample2 : List<List<Int?>>
checkSubtype<List<List<Int?>>>(sample2)
//breaks compiler
val sample3 = sample1.map({row -> row.map({column -> column})})
sample3 : List<List<Int?>>
checkSubtype<List<List<Int?>>>(sample3)
//doesn't break compiler
val identity: (Int?) -> Int? = {column -> column}
val sample4 = sample1.map({row -> row.map(identity)})
sample4 : List<List<Int?>>
checkSubtype<List<List<Int?>>>(sample4)
}
//------------
@@ -1,3 +1,5 @@
// !CHECK_TYPE
//KT-2200 array(array()) breaks compiler
package n
@@ -5,9 +7,9 @@ fun main(args: Array<String>) {
val <!UNUSED_VARIABLE!>a<!> = array(<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>array<!>())
val <!UNUSED_VARIABLE!>a0<!> : Array<Array<Int>> = array(array())
val a1 = array(array<Int>())
a1 : Array<Array<Int>>
checkSubtype<Array<Array<Int>>>(a1)
val a2 = array<Array<Int>>(array())
a2 : Array<Array<Int>>
checkSubtype<Array<Array<Int>>>(a2)
}
//from library
@@ -1,3 +1,5 @@
// !CHECK_TYPE
//KT-2294 Type inference infers DONT_CARE instead of correct type
package a
@@ -8,7 +10,7 @@ public fun test()
val x = foo(array(1, 2, 3, 4, 5)) // Should infer type 'Int'
// ^--- public final fun <T : kotlin.Any? > array(vararg t : DONT_CARE) : kotlin.Array<DONT_CARE> defined in Kotlin
// ^--- public final fun <E : kotlin.Any? > foo(items t : kotlin.Array<DONT_CARE>) : kotlin.Array<DONT_CARE> defined in root package
x : Array<Int>
checkSubtype<Array<Int>>(x)
}
//--------------------
@@ -1,3 +1,5 @@
// !CHECK_TYPE
//KT-2324 Can't resolve generic by type of function result
package i
@@ -13,11 +15,11 @@ fun <T, K> someFunction(list: List<T>, transform: (T) -> K): List<K> {
}
fun testSomeFunction() {
val result1 = someFunction(arrayList<Int>(1, 2), {it : Int}) //type of result1 is List<Int>
val result1 = someFunction(arrayList<Int>(1, 2), {checkSubtype<Int>(it)}) //type of result1 is List<Int>
assertEquals(1, result1.get(0)); //OK
val result2 = someFunction(arrayList<Int>(1, 2), {it}) // type of result2 is List<DONT_CARE>
result2 : List<Int>
checkSubtype<List<Int>>(result2)
assertEquals(1, result2.get(0)); //resolved to error element
}
@@ -1,11 +1,13 @@
// !CHECK_TYPE
package n
import java.util.*
fun test() {
val foo = arrayList("").map { it -> it.length() }.fold(0, { x, y -> Math.max(x, y) })
foo : Int
<!TYPE_MISMATCH!>foo<!> : String
checkSubtype<Int>(foo)
checkSubtype<String>(<!TYPE_MISMATCH!>foo<!>)
}
//from library
@@ -1,3 +1,5 @@
// !CHECK_TYPE
//KT-2505 Type mismatch: inferred type is T but T was expected
package a
@@ -16,5 +18,5 @@ public open class HttpResponse() {
fun test<R> (httpResponse: HttpResponse, rtype: MyClass<R>) {
val res = httpResponse.parseAs( rtype )
res : R //type mismatch: required R, found T
checkSubtype<R>(res) //type mismatch: required R, found T
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
//KT-731 Missing error from type inference
package a
@@ -12,5 +14,5 @@ fun <T, G> A<T>.foo(x: (T)-> G): G {
fun main(args: Array<String>) {
val a = A(1)
val t: String = a.<!TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>foo<!>({p -> p})
t : String
checkSubtype<String>(t)
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
//KT-943 Type inference failed
package maze
@@ -11,7 +13,7 @@ fun foo(lines: List<String>) {
val l2 = o2.length()
l1 - l2
}).sure()
w : String
checkSubtype<String>(w)
}
//standard library
@@ -1,3 +1,5 @@
// !CHECK_TYPE
//KT-948 Make type inference work with sure()/!!
package a
@@ -11,8 +13,8 @@ fun foo() {
val <!UNUSED_VARIABLE!>l<!> : List<Int> = emptyList()!!
val <!UNUSED_VARIABLE!>l1<!> = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>emptyList<!>()!!
emptyList()!! : List<Int>
emptyList() : List<Int>?
checkSubtype<List<Int>>(emptyList()!!)
checkSubtype<List<Int>?>(emptyList())
doWithList(emptyList()!!)
}