FIR checkers: report SMARTCAST_IMPOSSIBLE

This commit is contained in:
Tianyu Geng
2021-05-08 20:51:02 -07:00
committed by TeamCityServer
parent 2bb7ef9747
commit ce767046eb
58 changed files with 347 additions and 268 deletions
@@ -1,13 +0,0 @@
public class X {
private val x : String? = null
public val y: CharSequence?
get() = x?.subSequence(0, 1)
public fun fn(): Int {
if (y != null)
// With non-default getter smartcast is not possible
return y<!UNSAFE_CALL!>.<!>length
else
return 0
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
public class X {
private val x : String? = null
public val y: CharSequence?
@@ -1,11 +0,0 @@
public open class A() {
public open val foo: Int? = 1
}
infix fun Int.bar(i: Int) = i
fun test() {
val p = A()
// For open value properties, smart casts should not work
if (p.foo is Int) p.foo <!UNSAFE_INFIX_CALL!>bar<!> 11
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
public open class A() {
public open val foo: Int? = 1
}
@@ -1,35 +0,0 @@
// MODULE: m1
// FILE: a.kt
package a
public class X {
public val x : String? = null
}
// MODULE: m2(m1)
// FILE: b.kt
package b
import a.X
public fun X.gav(): Int {
if (x != null)
// Smart cast is not possible if definition is in another module
return x<!UNSAFE_CALL!>.<!>length
else
return 0
}
// FILE: c.kt
package a
public fun X.gav(): Int {
if (x != null)
// Even if it's in the same package
return x<!UNSAFE_CALL!>.<!>length
else
return 0
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// MODULE: m1
// FILE: a.kt
@@ -1,15 +0,0 @@
public class X {
public var x : String? = null
private var y: String? = "abc"
public fun fn(): Int {
if (x != null)
// Smartcast is not possible for variable properties
return x<!UNSAFE_CALL!>.<!>length
else if (y != null)
// Even if they are private
return y<!UNSAFE_CALL!>.<!>length
else
return 0
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
public class X {
public var x : String? = null
private var y: String? = "abc"