Preliminary declaration visitor for estimating local variable's predictability for smart casts
Predictability estimation algorithm is completely new, but backward compatibility should present. A large set of tests. Some updated tests. Smart casts allowed for captured variables if they are not modified in closure #KT-9051 Fixed Also #KT-8643 Fixed Also #KT-7976 Fixed Correct handling of lambda arguments in functions #KT-9143 Fixed
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
||||
class My {
|
||||
|
||||
val y: Int
|
||||
get() {
|
||||
var x: Int?
|
||||
x = 3
|
||||
return <!DEBUG_INFO_SMARTCAST!>x<!>.hashCode()
|
||||
}
|
||||
|
||||
fun test() {
|
||||
var x: Int?
|
||||
x = 2
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.hashCode()
|
||||
fun bb() {
|
||||
var <!NAME_SHADOWING!>x<!>: Any?
|
||||
x = 4
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.hashCode()
|
||||
}
|
||||
x = 4
|
||||
// Really smart cast is possible but name shadowing by bb() prevents it
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.hashCode()
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package
|
||||
|
||||
public final class My {
|
||||
public constructor My()
|
||||
public final val y: kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun test(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// FILE: My.java
|
||||
|
||||
public interface My {
|
||||
String foo(String arg);
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
class Your {
|
||||
val x = My() {
|
||||
arg: String? ->
|
||||
var y = arg
|
||||
val z: String
|
||||
if (y != null) z = <!DEBUG_INFO_SMARTCAST!>y<!>
|
||||
else z = "42"
|
||||
z
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package
|
||||
|
||||
public /*synthesized*/ fun My(/*0*/ function: (kotlin.String!) -> kotlin.String!): My
|
||||
|
||||
public interface My {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun foo(/*0*/ arg: kotlin.String!): kotlin.String!
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class Your {
|
||||
public constructor Your()
|
||||
public final val x: My
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun foo(x: Int, f: () -> Unit, y: Int) {}
|
||||
|
||||
fun bar() {
|
||||
var x: Int?
|
||||
x = 4
|
||||
foo(<!DEBUG_INFO_SMARTCAST!>x<!>, { x = null; x<!UNSAFE_CALL!>.<!>hashCode() }, <!SMARTCAST_IMPOSSIBLE!>x<!>)
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public fun bar(): kotlin.Unit
|
||||
public fun foo(/*0*/ x: kotlin.Int, /*1*/ f: () -> kotlin.Unit, /*2*/ y: kotlin.Int): kotlin.Unit
|
||||
Reference in New Issue
Block a user