KT-2729 Warn on 'T?' where 'T' has a nullable upper bound

This commit is contained in:
Andrey Breslav
2012-10-19 18:38:26 +04:00
parent 80039d8533
commit e8bd42b691
18 changed files with 63 additions and 20 deletions
@@ -1,4 +1,4 @@
fun fooT22<T>() : T? {
fun fooT22<T: Any>() : T? {
return null
}
@@ -1,10 +1,10 @@
package d
fun <T> joinT(<!UNUSED_PARAMETER!>x<!>: Int, vararg <!UNUSED_PARAMETER!>a<!>: T): T? {
fun <T: Any> joinT(<!UNUSED_PARAMETER!>x<!>: Int, vararg <!UNUSED_PARAMETER!>a<!>: T): T? {
return null
}
fun <T> joinT(<!UNUSED_PARAMETER!>x<!>: Any, <!UNUSED_PARAMETER!>y<!>: T): T? {
fun <T: Any> joinT(<!UNUSED_PARAMETER!>x<!>: Any, <!UNUSED_PARAMETER!>y<!>: T): T? {
return null
}
@@ -24,4 +24,4 @@ abstract class Buggy {
}
//from library
fun <T> Iterable<T>.find(<!UNUSED_PARAMETER!>predicate<!>: (T) -> Boolean) : T? {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T: Any> Iterable<T>.find(<!UNUSED_PARAMETER!>predicate<!>: (T) -> Boolean) : T? {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -6,8 +6,8 @@ trait MyType {}
class MyClass<T> : MyType {}
public open class HttpResponse() {
public open fun parseAs<T>(dataClass : MyClass<T>) : T? {
return null
public open fun parseAs<T>(dataClass : MyClass<T>) : T {
throw Exception()
}
public open fun parseAs(dataType : MyType) : Any? {
return null
@@ -16,5 +16,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?
res : R //type mismatch: required R, found T
}
@@ -6,7 +6,7 @@ fun getJavaClass<T>() : java.lang.Class<T> { <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_
public class Throwables() {
class object {
public fun propagateIfInstanceOf<X : Throwable?>(throwable : Throwable?, declaredType : Class<X?>?) : Unit {
public fun propagateIfInstanceOf<X : Throwable?>(throwable : Throwable?, declaredType : Class<X<!BASE_WITH_NULLABLE_UPPER_BOUND!>?<!>>?) : Unit {
if (((throwable != null) && declaredType?.isInstance(throwable)!!))
{
throw declaredType?.cast(throwable)!!
@@ -1,4 +1,4 @@
fun foo<T>(vararg <!UNUSED_PARAMETER!>ts<!>: T): T? = null
fun foo<T: Any>(vararg <!UNUSED_PARAMETER!>ts<!>: T): T? = null
class Pair<A>(a: A)