Tests for recently fixed bugs
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
// KT-174 Nullability info for extension function receivers
|
||||
// +JDK
|
||||
trait Tree {}
|
||||
|
||||
fun Any?.TreeValue() : Tree {
|
||||
if (this is Tree) return this
|
||||
throw Exception()
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// KT-201 Allow to call extension with nullable receiver with a '.'
|
||||
// +JDK
|
||||
|
||||
fun <T : Any> T?.npe() : T = if (this == null) throw NullPointerException() else this
|
||||
|
||||
fun foo() {
|
||||
val i : Int? = 1
|
||||
i.npe() // error!
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// KT-312 Nullability problem when a nullable version of a generic type is returned
|
||||
|
||||
fun <T> Array<out T>.safeGet(index : Int) : T? {
|
||||
return if (index < size) this[index] else null
|
||||
}
|
||||
|
||||
val args : Array<String> = Array<String>(1)
|
||||
val name : String = <!TYPE_MISMATCH!>args.safeGet<String>(0)<!> // No error, must be type mismatch
|
||||
val name1 : String? = args.safeGet(0)
|
||||
|
||||
Reference in New Issue
Block a user