Limit "always null" scope: only for !!, is and dot; senseless comparison rolled back; "smart constant" information for nulls #KT-10029 Fixed

This commit is contained in:
Mikhail Glukhikh
2015-11-23 14:50:20 +03:00
parent db42941586
commit 89e56093a2
41 changed files with 323 additions and 151 deletions
@@ -1,11 +1,23 @@
fun foo(): String {
var s: String?
s = null
<!ALWAYS_NULL!>s<!>?.length
if (<!ALWAYS_NULL!>s<!> == null) s = "z"
<!DEBUG_INFO_CONSTANT!>s<!>?.length
<!ALWAYS_NULL!>s<!><!UNSAFE_CALL!>.<!>length
if (<!SENSELESS_COMPARISON!><!DEBUG_INFO_CONSTANT!>s<!> == null<!>) return <!ALWAYS_NULL!>s<!>!!
var t: String? = "y"
if (t == null) t = "x"
var x: Int? = null
if (x == null) <!TYPE_MISMATCH!>x += null<!>
return <!DEBUG_INFO_SMARTCAST!>t<!> + s
}
fun String?.gav() {}
fun bar(s: String?) {
if (s != null) return
// Ideally we should have DEBUG_INFO_CONSTANT instead
<!ALWAYS_NULL!>s<!>.gav()
<!DEBUG_INFO_CONSTANT!>s<!> as? String
<!DEBUG_INFO_CONSTANT!>s<!> <!USELESS_CAST!>as String?<!>
<!ALWAYS_NULL!>s<!> as String
}
@@ -1,3 +1,5 @@
package
public fun bar(/*0*/ s: kotlin.String?): kotlin.Unit
public fun foo(): kotlin.String
public fun kotlin.String?.gav(): kotlin.Unit
@@ -0,0 +1,16 @@
// FILE: My.java
public class My {
static public My create() { return new My(); }
public void foo() {}
}
// FILE: Test.kt
fun test() {
val my = My.create()
if (my == null) {
<!ALWAYS_NULL!>my<!>.foo()
}
}
@@ -0,0 +1,14 @@
package
public fun test(): kotlin.Unit
public open class My {
public constructor My()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
// Static members
public open fun create(): My!
}
@@ -8,7 +8,7 @@ fun foo(x : String?, y : String?) {
x<!UNSAFE_CALL!>.<!>length
y<!UNSAFE_CALL!>.<!>length
}
if (y != null || x == <!ALWAYS_NULL!>y<!>) {
if (y != null || x == <!DEBUG_INFO_CONSTANT!>y<!>) {
x<!UNSAFE_CALL!>.<!>length
y<!UNSAFE_CALL!>.<!>length
}
@@ -17,7 +17,7 @@ fun foo(x : String?, y : String?) {
<!DEBUG_INFO_SMARTCAST!>x<!>.length
<!ALWAYS_NULL!>y<!><!UNSAFE_CALL!>.<!>length
}
if (y == null && x != <!ALWAYS_NULL!>y<!>) {
if (y == null && x != <!DEBUG_INFO_CONSTANT!>y<!>) {
// y == null but x != y
<!DEBUG_INFO_SMARTCAST!>x<!>.length
<!ALWAYS_NULL!>y<!><!UNSAFE_CALL!>.<!>length
@@ -3,7 +3,7 @@ fun foo(x: String?, y: String?, z: String?, w: String?) {
<!DEBUG_INFO_SMARTCAST!>z<!>.length
else
z<!UNSAFE_CALL!>.<!>length
if (x != null || y != null || (<!ALWAYS_NULL!>x<!> != z && <!ALWAYS_NULL!>y<!> != z))
if (x != null || y != null || (<!DEBUG_INFO_CONSTANT!>x<!> != z && <!DEBUG_INFO_CONSTANT!>y<!> != z))
z<!UNSAFE_CALL!>.<!>length
else
<!ALWAYS_NULL!>z<!><!UNSAFE_CALL!>.<!>length
@@ -1,6 +1,6 @@
fun bar(x: Int?): Int {
if (x != null) return -1
if (<!ALWAYS_NULL!>x<!> == null) return -2
if (<!SENSELESS_COMPARISON!><!DEBUG_INFO_CONSTANT!>x<!> == null<!>) return -2
// Should be unreachable
return 2 + 2
}
@@ -1,5 +1,5 @@
fun foo(): Int {
var i: Int? = <!VARIABLE_WITH_REDUNDANT_INITIALIZER!>42<!>
i = null
return <!ALWAYS_NULL!>i<!> <!UNSAFE_INFIX_CALL!>+<!> 1
return <!DEBUG_INFO_CONSTANT!>i<!> <!UNSAFE_INFIX_CALL!>+<!> 1
}