FIR DFA: smartcast variable to Nothing? on null assignment
In order to make resolution still work for members not available from `Nothing`, we track the type without `Nothing?` and use that for resolution instead.
This commit is contained in:
committed by
teamcityserver
parent
7e2f15f532
commit
4726dcce40
@@ -7,7 +7,7 @@ fun foo(): String {
|
||||
var t: String? = "y"
|
||||
if (t == null) t = "x"
|
||||
var x: Int? = null
|
||||
if (x == null) x <!UNSAFE_OPERATOR_CALL!>+=<!> null
|
||||
if (x == null) <!ASSIGNMENT_TYPE_MISMATCH!>x += null<!>
|
||||
return t + s
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ fun String?.gav() {}
|
||||
fun bar(s: String?) {
|
||||
if (s != null) return
|
||||
s.gav()
|
||||
s <!USELESS_CAST!>as? String<!>
|
||||
s <!USELESS_CAST!>as String?<!>
|
||||
s as? String
|
||||
s as String?
|
||||
s as String
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
// 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) {
|
||||
my.foo()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// FILE: My.java
|
||||
|
||||
public class My {
|
||||
|
||||
@@ -7,14 +7,14 @@ class TestWithEquals {
|
||||
}
|
||||
|
||||
fun bar(i: Test?) {
|
||||
if (i == null) foo(<!ARGUMENT_TYPE_MISMATCH!>i<!>)
|
||||
if (i == null) foo(i)
|
||||
}
|
||||
|
||||
fun bar(i: TestWithEquals?) {
|
||||
if (i == null) foo(<!ARGUMENT_TYPE_MISMATCH!>i<!>)
|
||||
if (null == i) foo(<!ARGUMENT_TYPE_MISMATCH!>i<!>)
|
||||
if (i == null) foo(i)
|
||||
if (null == i) foo(i)
|
||||
when (i) {
|
||||
null -> foo(<!ARGUMENT_TYPE_MISMATCH!>i<!>)
|
||||
null -> foo(i)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,4 +22,4 @@ fun gav(i: TestWithEquals?, j: TestWithEquals?) {
|
||||
if (j == null) {
|
||||
if (i == j) foo(<!ARGUMENT_TYPE_MISMATCH!>i<!>)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -19,11 +19,11 @@ fun g(x: B<Int>) {
|
||||
val y = x.content
|
||||
if (y == null) {
|
||||
f(y)
|
||||
g(y)
|
||||
<!NONE_APPLICABLE!>g<!>(y)
|
||||
}
|
||||
|
||||
if (y is Nothing?) {
|
||||
f(y)
|
||||
g(y)
|
||||
<!NONE_APPLICABLE!>g<!>(y)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun foo(): Int {
|
||||
var i: Int? = 42
|
||||
i = null
|
||||
return i <!UNSAFE_OPERATOR_CALL!>+<!> 1
|
||||
return <!RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>i + 1<!>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user