Revert "FIR checkers: report SMARTCAST_IMPOSSIBLE"

This reverts commit 84334b08
This commit is contained in:
Dmitriy Novozhilov
2021-06-03 09:48:50 +03:00
parent 20d1a84002
commit 796f8e6bce
51 changed files with 297 additions and 308 deletions
@@ -0,0 +1,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface Ctx
class CtxImpl : Ctx {
fun doJob(a: Int) {}
fun doJob(s: String) {}
}
open class Test(open val ctx: Ctx) {
fun test() {
when (ctx) {
is CtxImpl -> ctx.<!UNRESOLVED_REFERENCE!>doJob<!>(2)
}
}
}
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface Ctx
@@ -0,0 +1,14 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A
class B
fun A.foo(a: A) {}
fun A.foo(b: B) {}
var a: A? = null
fun smartCastInterference(b: B) {
if (a != null) {
a<!UNSAFE_CALL!>.<!>foo(b)
}
}
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A
@@ -0,0 +1,11 @@
class A<E> {
fun foo(): E = TODO()
}
class B(var a: A<*>?) {
fun bar() {
if (a != null) {
a<!UNSAFE_CALL!>.<!>foo()
}
}
}
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
class A<E> {
fun foo(): E = TODO()
}
@@ -0,0 +1,16 @@
open class A<E> {
}
class B : A<String>() {
fun foo() {}
}
interface KI {
val a: A<*>
}
fun KI.bar() {
if (a is B) {
a.<!UNRESOLVED_REFERENCE!>foo<!>()
}
}
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
open class A<E> {
}
@@ -0,0 +1,37 @@
// !CHECK_TYPE
interface A {
fun foo(): CharSequence?
fun baz(x: Any) {}
}
interface B {
fun foo(): String
fun baz(x: Int): String =""
fun baz(x: Int, y: Int) {}
fun foobar(): CharSequence?
}
interface C {
fun foo(): String
fun baz(x: Int): String =""
fun baz(x: Int, y: Int) {}
fun foobar(): String
}
var x: A = null!!
fun test() {
x.foo().checkType { _<CharSequence?>() }
if (x is B && x is C) {
x.foo().checkType { _<CharSequence?>() }
x.baz("")
x.baz(1).checkType { _<Unit>() }
x.baz(1, <!TOO_MANY_ARGUMENTS!>2<!>)
x.<!UNRESOLVED_REFERENCE!>foobar<!>().checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
}
}
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
// !CHECK_TYPE
interface A {
@@ -10,6 +10,6 @@ fun failsWithClassCastException() {
val sometimesNotInt: Any? by AlternatingDelegate()
if (sometimesNotInt is Int) {
<!SMARTCAST_IMPOSSIBLE!>sometimesNotInt<!>.inc()
sometimesNotInt.inc()
}
}
}
@@ -10,6 +10,6 @@ fun failsWithClassCastException() {
val sometimesNotInt: Any? by AlternatingDelegate()
if (sometimesNotInt is Int) {
<!SMARTCAST_IMPOSSIBLE!>sometimesNotInt<!>.inc()
sometimesNotInt.inc()
}
}
}
@@ -2,7 +2,7 @@ sealed class My(open val x: Int?) {
init {
if (x != null) {
// Should be error: property is open
<!SMARTCAST_IMPOSSIBLE!>x<!>.hashCode()
x<!UNSAFE_CALL!>.<!>hashCode()
}
}
}
@@ -7,7 +7,7 @@ class Immutable(val x: String?) {
class Mutable(var y: String?) {
fun foo(): String {
if (y != null) return <!SMARTCAST_IMPOSSIBLE!>y<!>
if (y != null) return <!RETURN_TYPE_MISMATCH!>y<!>
return ""
}
}
@@ -0,0 +1,13 @@
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,4 +1,3 @@
// FIR_IDENTICAL
public class X {
private val x : String? = null
public val y: CharSequence?
@@ -0,0 +1,11 @@
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,4 +1,3 @@
// FIR_IDENTICAL
public open class A() {
public open val foo: Int? = 1
}
@@ -0,0 +1,35 @@
// 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,4 +1,3 @@
// FIR_IDENTICAL
// MODULE: m1
// FILE: a.kt
@@ -0,0 +1,15 @@
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,4 +1,3 @@
// FIR_IDENTICAL
public class X {
public var x : String? = null
private var y: String? = "abc"
@@ -0,0 +1,18 @@
class Foo(var x: Int?) {
init {
if (x != null) {
val y = x
// Error: x is not stable, Type(y) = Int?
x<!UNSAFE_CALL!>.<!>hashCode()
y<!UNSAFE_CALL!>.<!>hashCode()
if (y == x) {
// Still error
y<!UNSAFE_CALL!>.<!>hashCode()
}
if (x == null && y != x) {
// Still error
y<!UNSAFE_CALL!>.<!>hashCode()
}
}
}
}
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
class Foo(var x: Int?) {
init {
if (x != null) {
@@ -0,0 +1,22 @@
class Bar {
fun bar() {}
}
class Foo(var x: Any) {
init {
if (x is Bar) {
val y = x
// Error: x is not stable, Type(y) = Any
x.<!UNRESOLVED_REFERENCE!>bar<!>()
y.<!UNRESOLVED_REFERENCE!>bar<!>()
if (y == x) {
// Still error
y.<!UNRESOLVED_REFERENCE!>bar<!>()
}
if (x !is Bar && y != x) {
// Still error
y.<!UNRESOLVED_REFERENCE!>bar<!>()
}
}
}
}
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
class Bar {
fun bar() {}
}