Smart casts to nothing after comparison with null
This commit is contained in:
committed by
Mikhail Glukhikh
parent
981d471ebe
commit
b556037915
@@ -3,19 +3,19 @@ fun bar(x: Int) = x + 1
|
||||
fun f1(x: Int?) {
|
||||
bar(<!TYPE_MISMATCH!>x<!>)
|
||||
if (x != null) bar(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
|
||||
if (x == null) bar(x!!)
|
||||
if (x == null) <!UNREACHABLE_CODE!>bar(<!><!DEBUG_INFO_SMARTCAST!>x<!>!!<!UNREACHABLE_CODE!>)<!>
|
||||
}
|
||||
|
||||
fun f2(x: Int?) {
|
||||
if (x != null) else bar(x!!)
|
||||
if (x != null) else <!DEBUG_INFO_SMARTCAST!>x<!>!!
|
||||
}
|
||||
|
||||
fun f3(x: Int?) {
|
||||
if (x != null) bar(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>) else bar(x!!)
|
||||
if (x != null) bar(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>) else <!DEBUG_INFO_SMARTCAST!>x<!>!!
|
||||
}
|
||||
|
||||
fun f4(x: Int?) {
|
||||
if (x == null) bar(x!!) else bar(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
|
||||
if (x == null) <!DEBUG_INFO_SMARTCAST!>x<!>!! else bar(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
|
||||
}
|
||||
|
||||
fun f5(x: Int?) {
|
||||
|
||||
@@ -22,8 +22,8 @@ fun main(args : Array<String>) {
|
||||
foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
|
||||
} else {
|
||||
foo(<!TYPE_MISMATCH!>x<!>)
|
||||
foo(x!!)
|
||||
foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
|
||||
<!UNREACHABLE_CODE!>foo(<!><!DEBUG_INFO_SMARTCAST!>x<!>!!<!UNREACHABLE_CODE!>)<!>
|
||||
<!UNREACHABLE_CODE!>foo(<!DEBUG_INFO_SMARTCAST!>x<!>)<!>
|
||||
}
|
||||
|
||||
foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
|
||||
|
||||
Vendored
+2
-2
@@ -2,13 +2,13 @@ fun <T> test(t: T): T {
|
||||
if (t != null) {
|
||||
return t<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
}
|
||||
return t!!
|
||||
return <!DEBUG_INFO_SMARTCAST!>t<!>!!
|
||||
}
|
||||
|
||||
fun <T> T.testThis(): String {
|
||||
if (this != null) {
|
||||
return this<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.toString()
|
||||
}
|
||||
return this!!.toString()
|
||||
return <!DEBUG_INFO_SMARTCAST!>this<!>!!.toString()
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
fun bar(x: Int?): Int {
|
||||
if (x != null) return -1
|
||||
if (<!SENSELESS_COMPARISON!>x == null<!>) return -2
|
||||
// Should be unreachable
|
||||
return 2 + 2
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
public fun bar(/*0*/ x: kotlin.Int?): kotlin.Int
|
||||
Reference in New Issue
Block a user