Fix the case of safe call and elvis operators: flexible types may be nullable

This commit is contained in:
Andrey Breslav
2014-06-30 15:36:46 +04:00
parent 45c1fa3741
commit 195274370f
6 changed files with 59 additions and 9 deletions
@@ -1,11 +1,11 @@
fun <T> test(t: T): String {
fun <T> test(t: T): String? {
if (t != null) {
return t<!UNNECESSARY_SAFE_CALL!>?.<!>toString()
}
return t?.toString()
}
fun <T> T.testThis(): String {
fun <T> T.testThis(): String? {
if (this != null) {
return this<!UNNECESSARY_SAFE_CALL!>?.<!>toString()
}
@@ -0,0 +1,14 @@
// FILE: p/J.java
package p;
public class J {
public String s() { return null; }
}
// FILE: k.kt
import p.*
fun test(j: J) {
j.s()?.length ?: ""
}
@@ -0,0 +1,15 @@
// !CHECK_TYPE
// FILE: p/J.java
package p;
public class J {
public String s() { return null; }
}
// FILE: k.kt
import p.*
fun test(j: J) {
j.s()?.length.checkType { it : _<Int?> }
}