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
@@ -6,7 +6,7 @@ fun <T: Any> bar(a: Array<T>): Array<T?> = null!!
fun test1(a: Array<out Int>) {
val r: Array<out Int?> = bar(a)
val t = bar(a)
t checkType { it : _<Array<out Int?>> }
t checkType { _<Array<out Int?>>() }
}
fun <T: Any> foo(l: Array<T>): Array<Array<T?>> = null!!
@@ -14,5 +14,5 @@ fun <T: Any> foo(l: Array<T>): Array<Array<T?>> = null!!
fun test2(a: Array<out Int>) {
val r: Array<out Array<out Int?>> = foo(a)
val t = foo(a)
t checkType { it : _<Array<out Array<out Int?>>> }
t checkType { _<Array<out Array<out Int?>>>() }
}
@@ -15,15 +15,15 @@ public class A {
fun test1(clazz: Class<out Int>) {
val foo0: Class<out Int> = A.foo(clazz)
val foo1 = A.foo(clazz)
foo1 checkType { it: _< Class<out Int> > }
foo1 checkType { _< Class<out Int> >() }
// should be ok
foo1 checkType { <!TYPE_MISMATCH!>it<!>: _< Class<out Int?> > }
foo1 checkType { <!TYPE_MISMATCH!>_<!>< Class<out Int?> >() }
}
fun tes2t(clazz: Class<in Int>) {
val foo0: Class<out Class<in Int>> = A.bar(clazz)
val foo1 = A.bar(clazz)
foo1 checkType { it: _< Class<out Class<in Int>> > }
foo1 checkType { _< Class<out Class<in Int>> >() }
// should be ok
foo1 checkType { <!TYPE_MISMATCH!>it<!>: _< Class<out Class<in Int?>> > }
foo1 checkType { <!TYPE_MISMATCH!>_<!>< Class<out Class<in Int?>> >() }
}
@@ -4,10 +4,10 @@ fun <T : Any> Array<T?>.filterNotNull(): List<T> = throw Exception()
fun test1(a: Array<out Int?>) {
val list = a.filterNotNull()
list checkType { it : _<List<Int>> }
list checkType { _<List<Int>>() }
}
fun test2(vararg a: Int?) {
val list = a.filterNotNull()
list checkType { it : _<List<Int>> }
list checkType { _<List<Int>>() }
}
@@ -6,11 +6,11 @@ fun <T> foo(array: Array<T>): Array<T> = array
fun test1(a1: Array<out Int>) {
val b1: Array<out Int> = foo(a1)
val c1 = foo(a1)
c1 checkType { it : _<Array<out Int>> }
c1 checkType { _<Array<out Int>>() }
}
fun test2(a2: Array<in Int>) {
val b2: Array<in Int> = foo(a2)
val c2 = foo(a2)
c2 checkType { it : _<Array<in Int>> }
c2 checkType { _<Array<in Int>>() }
}
@@ -6,11 +6,11 @@ fun <T> foo(a: Array<T>): Array<Array<T>> = throw Exception()
fun test1(a1: Array<out Int>) {
val b1: Array<out Array<out Int>> = foo(a1)
val c1 = foo(a1)
c1 checkType { it : _<Array<out Array<out Int>>> }
c1 checkType { _<Array<out Array<out Int>>>() }
}
fun test2(a2: Array<in Int>) {
val b2: Array<out Array<in Int>> = foo(a2)
val c2 = foo(a2)
c2 checkType { it : _<Array<out Array<in Int>>> }
c2 checkType { _<Array<out Array<in Int>>>() }
}
@@ -4,11 +4,11 @@
fun <T> foo1(a1: Array<in T>, a2: Array<T>): T = null!!
fun test1(a1: Array<Int>, a2: Array<out Int>) {
foo1(a1, a2) checkType { it : _<Int> }
foo1(a1, a2) checkType { _<Int>() }
}
fun <T> foo2(a1: Array<T>, a2: Array<out T>): T = null!!
fun test2(a1: Array<in Int>, a2: Array<Int>) {
foo2(a1, a2) checkType { it : _<Any?>}
foo2(a1, a2) checkType { _<Any?>() }
}
@@ -5,5 +5,5 @@ fun <T> foo(l: MutableList<T>): MutableList<T> = l
fun test(l: MutableList<out Int>) {
val a: MutableList<out Int> = foo(l)
val b = foo(l)
b checkType { it: _< MutableList<out Int> > }
b checkType { _< MutableList<out Int> >() }
}
@@ -4,5 +4,5 @@
fun <T> foo(a: Array<T>): T = null!!
fun test(a: Array<in Int>) {
foo(a) checkType { it : _<Any?> }
foo(a) checkType { _<Any?>() }
}
@@ -4,5 +4,5 @@
fun <T> foo(a: Array<T>): T = null!!
fun test(a: Array<out Int>) {
foo(a) checkType { it : _<Int> }
foo(a) checkType { _<Int>() }
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
package d
fun <T: Any> joinT(<!UNUSED_PARAMETER!>x<!>: Int, vararg <!UNUSED_PARAMETER!>a<!>: T): T? {
@@ -10,6 +12,6 @@ fun <T: Any> joinT(<!UNUSED_PARAMETER!>x<!>: Any, <!UNUSED_PARAMETER!>y<!>: T):
fun test() {
val x2 = joinT(<!NON_VARARG_SPREAD!>*<!>1, "2")
x2 : String?
checkSubtype<String?>(x2)
}
@@ -8,13 +8,13 @@ fun <T> doA(a: A<T>): T = throw Exception("$a")
fun test(a: A<Int>, aN: A<Int?>) {
val aa = doA(aN)
aa checkType { it : _<Int?> }
aa checkType { _<Int?>() }
val nullable = foo(aN, aN)
//T = Int?, T? = Int? => T = Int?
nullable checkType { it : _<Int?> }
nullable checkType { _<Int?>() }
val notNullable = foo(a, aN)
//T = Int, T? = Int? => T = Int
notNullable checkType { it : _<Int> }
notNullable checkType { _<Int>() }
}
@@ -7,9 +7,9 @@ fun <T> foo1(f: (T) -> Unit): Foo<T> = Foo()
inline fun <reified T> foo2(f: (T) -> Unit): Foo<T> = Foo()
fun test1() {
val f1: Foo<out Int> = foo1 { it checkType { it : _<Int> } }
val f2: Foo<in Nothing> = foo1 { it <!UNREACHABLE_CODE!>checkType { it : _<Nothing> }<!> }
val f1: Foo<out Int> = foo1 { it checkType { _<Int>() } }
val f2: Foo<in Nothing> = foo1 { it <!UNREACHABLE_CODE!>checkType { _<Nothing>() }<!> }
val f3: Foo<out Int> = foo2 { it checkType { it : _<Int> } }
val f4: Foo<in Nothing> = <!REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>foo2<!> { it <!UNREACHABLE_CODE!>checkType { it : _<Nothing> }<!> }
val f3: Foo<out Int> = foo2 { it checkType { _<Int>() } }
val f4: Foo<in Nothing> = <!REIFIED_TYPE_FORBIDDEN_SUBSTITUTION!>foo2<!> { it <!UNREACHABLE_CODE!>checkType { _<Nothing>() }<!> }
}
@@ -14,7 +14,7 @@ fun test(out: Out<Int>, i: In<Int>, inv: A<Int>) {
// T? >: Int => T = Int
doT(1)
val r = doOut(out)
r checkType { it : _<Int> }
r checkType { _<Int>() }
// T? <: Int => error
doIn(<!TYPE_MISMATCH!>i<!>)
@@ -11,13 +11,13 @@ fun <T> doOut(o: Out<T?>): T = throw Exception("$o")
fun test(a: A<Int>, aN: A<Int?>, o: Out<Int?>) {
val out = doOut(o)
//T? >: Int? => T >: Int
out checkType { it : _<Int> }
out checkType { _<Int>() }
val nullable = foo(aN, o)
//T = Int?, T? >: Int? => T = Int?
nullable checkType { it : _<Int?> }
nullable checkType { _<Int?>() }
val notNullable = foo(a, o)
//T = Int, T? >: Int? => T = Int
notNullable checkType { it : _<Int> }
notNullable checkType { _<Int>() }
}
@@ -11,13 +11,13 @@ fun <T> doIn(i: In<T?>): T = throw Exception("$i")
fun test(a: A<Int>, aN: A<Int?>, i: In<Int?>) {
val _in = doIn(i)
//T? <: Int? => T <: Int?
_in checkType { it : _<Int?> }
_in checkType { _<Int?>() }
val notNullable = foo(a, i)
//T = Int, T? <: Int? => T = Int
notNullable checkType { it : _<Int> }
notNullable checkType { _<Int>() }
val nullable = foo(aN, i)
//T = Int?, T? <: Int? => T = Int?
nullable checkType { it : _<Int?> }
nullable checkType { _<Int?>() }
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
package h
//+JDK
import java.util.*
@@ -16,28 +18,28 @@ fun test1() {
val a = elem(list(2))
val b = id(elem(list(2)))
val c = id(id1(id(id1(list(33)))))
a : Int
b : Int
c : List<Int>
checkSubtype<Int>(a)
checkSubtype<Int>(b)
checkSubtype<List<Int>>(c)
val d : ArrayList<Int> = newList()
val e : ArrayList<Int> = id(newList())
val f : ArrayList<Int> = id(id1(id(id1(newList()))))
d : List<Int>
e : List<Int>
f : List<Int>
checkSubtype<List<Int>>(d)
checkSubtype<List<Int>>(e)
checkSubtype<List<Int>>(f)
val g = elemAndList("", newList())
val h = elemAndList<Long>(1, newList<Long>())
g : String
h : Long
checkSubtype<String>(g)
checkSubtype<Long>(h)
val i = both(1, "")
val j = both(id(1), id(""))
i : Comparable<*>
j : Comparable<*>
checkSubtype<Comparable<*>>(i)
checkSubtype<Comparable<*>>(j)
}
fun list<T>(value: T) : ArrayList<T> {
@@ -1,3 +1,5 @@
// !CHECK_TYPE
package a
fun <T> emptyList(): List<T> = throw Exception()
@@ -6,7 +8,7 @@ fun foo<T>(f: T.() -> Unit, l: List<T>): T = throw Exception("$f$l")
fun test() {
val q = foo(fun Int.() {}, emptyList()) //type inference no information for parameter error
q: Int
checkSubtype<Int>(q)
<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>({}, <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>emptyList<!>())
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
package a
//+JDK
import java.util.*
@@ -11,9 +13,9 @@ fun test() {
val xs1 = cons("", nil())
val xs2 = cons(1, nil<Any>())
xs : List<Int>
xs1 : List<String>
xs2 : List<Any>
checkSubtype<List<Int>>(xs)
checkSubtype<List<String>>(xs1)
checkSubtype<List<Any>>(xs2)
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
package a
//+JDK
@@ -8,17 +10,17 @@ fun foo() {
val u = v map { it * 2 }
u : List<Int>
checkSubtype<List<Int>>(u)
val a = 1..5
val b = a.map { it * 2 }
b : List<Int>
checkSubtype<List<Int>>(b)
//check for non-error types
<!TYPE_MISMATCH!>u<!> : String
<!TYPE_MISMATCH!>b<!> : String
checkSubtype<String>(<!TYPE_MISMATCH!>u<!>)
checkSubtype<String>(<!TYPE_MISMATCH!>b<!>)
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
package i
//+JDK
@@ -9,7 +11,7 @@ fun <T, R> <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Iterable<T><!>.map1(<!UN
fun test(list: List<Int>) {
val res = list.map1 { it }
//check res is not of error type
<!TYPE_MISMATCH!>res<!> : String
checkSubtype<String>(<!TYPE_MISMATCH!>res<!>)
}
fun <T> Collection<T>.foo() {}
@@ -18,5 +20,5 @@ fun <T> <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Iterable<T><!>.foo() {}
fun test1(list: List<Int>) {
val res = list.foo()
//check res is not of error type
<!TYPE_MISMATCH!>res<!> : String
checkSubtype<String>(<!TYPE_MISMATCH!>res<!>)
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
package aaa
fun <T> T.foo(t: T) = t
@@ -6,5 +8,5 @@ fun id<T>(t: T) = t
fun a() {
val i = id(2 foo 3)
i : Int // i shouldn't be resolved to error element
checkSubtype<Int>(i) // i shouldn't be resolved to error element
}
@@ -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()!!)
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
package g
import java.util.HashSet
@@ -6,5 +8,5 @@ fun <T, C: Collection<T>> convert(src: Collection<T>, dest: C): C = throw Except
fun test(l: List<Int>) {
//todo should be inferred
val r = <!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>convert<!>(l, <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>HashSet<!>())
<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>r<!>: Int
checkSubtype<Int>(<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>r<!>)
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
package s
trait In<in T>
@@ -13,7 +15,7 @@ fun test(inA: In<A>, inB: In<B>, inC: In<C>) {
<!TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>foo<!>(inA, inB)
val r = foo(inA, inC)
r: C
checkSubtype<C>(r)
val c: C = foo(inA, inB)
@@ -24,7 +26,7 @@ fun <T: C> bar(in1: In<T>): T = throw Exception("$in1")
fun test(inA: In<A>) {
val r = bar(inA)
r: C
checkSubtype<C>(r)
}
fun use(vararg a: Any?) = a