Elvis DFA: now only left part is taken into account #KT-9100 Fixed

I had to fix a few incorrect tests using something like x!! in Elvis right part, and also one bug in our code
This commit is contained in:
Mikhail Glukhikh
2015-09-09 15:59:06 +03:00
committed by Mikhail Glukhikh
parent 9fd968d59e
commit 9b11b5300c
13 changed files with 103 additions and 13 deletions
@@ -0,0 +1,9 @@
// Based on KT-9100
fun test(x: Any?, y: Any?): Any {
val z = x ?: y!!
y<!UNSAFE_CALL!>.<!>hashCode()
// !! / ?. is necessary here, because y!! above may not be executed
y?.hashCode()
y!!.hashCode()
return z
}
@@ -0,0 +1,3 @@
package
public fun test(/*0*/ x: kotlin.Any?, /*1*/ y: kotlin.Any?): kotlin.Any
@@ -0,0 +1,6 @@
fun test(x: Any?): Any {
val z = x ?: x!!
// x is not null in both branches
<!DEBUG_INFO_SMARTCAST!>x<!>.hashCode()
return z
}
@@ -0,0 +1,3 @@
package
public fun test(/*0*/ x: kotlin.Any?): kotlin.Any
@@ -0,0 +1,27 @@
// FILE: p/My.java
package p;
import org.jetbrains.annotations.*;
class My {
@Nullable static String create() {
return "";
}
}
// FILE: test.kt
package p
fun bar(x: String) = x
fun test(x: String?): Any {
val y = My.create()
val z = x ?: y!!
bar(<!TYPE_MISMATCH!>y<!>)
// !! / ?. is necessary here, because y!! above may not be executed
y?.hashCode()
y!!.hashCode()
return z
}
@@ -0,0 +1,16 @@
package
package p {
public fun bar(/*0*/ x: kotlin.String): kotlin.String
public fun test(/*0*/ x: kotlin.String?): kotlin.Any
public/*package*/ open class My {
public/*package*/ constructor 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
// Static members
org.jetbrains.annotations.Nullable() public/*package*/ open fun create(): kotlin.String?
}
}
@@ -3,8 +3,8 @@ public fun foo(x: String?, y: String?): Int {
val z = x ?: if (y == null) break else <!DEBUG_INFO_SMARTCAST!>y<!>
// z is not null in both branches
z.length()
// y is not null in both branches
<!DEBUG_INFO_SMARTCAST!>y<!>.length()
// y is nullable if x != null
y<!UNSAFE_CALL!>.<!>length()
}
// y is null because of the break
return y<!UNSAFE_CALL!>.<!>length()
@@ -1,8 +1,8 @@
public fun foo(x: String?, y: String?): Int {
while (true) {
x ?: if (y == null) break
// y is not null in both branches
<!DEBUG_INFO_SMARTCAST!>y<!>.length()
// y is nullable if x != null
y<!UNSAFE_CALL!>.<!>length()
}
// y is null because of the break
return y<!UNSAFE_CALL!>.<!>length()
@@ -1,8 +1,8 @@
public fun foo(x: String?, y: String?): Int {
while (true) {
(if (x != null) break else y) ?: y!!
// x is not null in both branches
<!DEBUG_INFO_SMARTCAST!>y<!>.length()
// y is not null in both branches but it's hard to determine
y<!UNSAFE_CALL!>.<!>length()
}
// y can be null because of the break
return y<!UNSAFE_CALL!>.<!>length()