[FIR] Implement UNRESOLVED_REFERENCE_WRONG_RECEIVER

This commit is contained in:
Ivan Kochurkin
2021-08-10 16:40:51 +03:00
committed by Space
parent 34cc7e5199
commit 84c5f58cab
129 changed files with 322 additions and 481 deletions
@@ -24,9 +24,9 @@ private class Outer<E> {
doubleStringInt = Outer<Double>().Inner<String>().foo<Int>()()
doubleStringInt.e.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Double>() }
doubleStringInt.f.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
doubleStringInt.g.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Int>() }
doubleStringInt.e.checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Double>() }
doubleStringInt.f.checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><String>() }
doubleStringInt.g.checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Int>() }
}
}
}
@@ -18,7 +18,7 @@ class Q {
x = foo<CharSequence>()()
y = foo<String>()()
x.prop.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><CharSequence>() }
y.prop.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
x.prop.checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><CharSequence>() }
y.prop.checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><String>() }
}
}
@@ -15,8 +15,8 @@ class Q {
private var x = foo<CharSequence, Number>()()
fun bar() {
x.e.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><CharSequence>() }
x.f.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Number>() }
x.e.checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><CharSequence>() }
x.f.checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Number>() }
x.g.checkType { _<Number>() }
}
}
@@ -20,7 +20,7 @@ class A : Outer<Double, Short>() {
fun foo() {
Derived().foo() checkType { _<Outer<String, Int>.Inner<Char>>() }
Derived().baz() <!INAPPLICABLE_CANDIDATE!>checkType<!> { _<Map<Char, String>>() }
Derived().baz() <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<Map<Char, String>>() }
A.B().bar() checkType { _<Outer<Float, Long>.Inner<String>>() }
A.B().x() <!INAPPLICABLE_CANDIDATE!>checkType<!> { _<Map<String, Float>>() }
A.B().x() <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<Map<String, Float>>() }
}
@@ -41,8 +41,8 @@ fun test() {
var x = foobar<String>()
x = foobar<String>()
x().foo().a() checkType { <!INAPPLICABLE_CANDIDATE!>_<!><A<String, Double, Short, Long>>() }
x().bar() <!INAPPLICABLE_CANDIDATE!>checkType<!> { _<A<String, Double, Short, Char>>() }
x().foo().a() checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><A<String, Double, Short, Long>>() }
x().bar() <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<A<String, Double, Short, Char>>() }
x = foobar<Int>()
@@ -50,5 +50,5 @@ fun test() {
y = noParameters()
y().foo().a() checkType { _<A<Any, Double, Short, Long>>() }
y().bar() <!INAPPLICABLE_CANDIDATE!>checkType<!> { _<A<Any, Double, Short, Char>>() }
y().bar() <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<A<Any, Double, Short, Char>>() }
}
@@ -42,8 +42,8 @@ class Outer<T> {
var x = foobar<String>()
x = foobar<String>()
x().foo().a() checkType { <!INAPPLICABLE_CANDIDATE!>_<!><A<T, F, String, Double, Short, Long>>() }
x().bar() <!INAPPLICABLE_CANDIDATE!>checkType<!> { _<A<T, F, String, Double, Short, Char>>() }
x().foo().a() checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><A<T, F, String, Double, Short, Long>>() }
x().bar() <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<A<T, F, String, Double, Short, Char>>() }
x = foobar<Int>()
x = z.foobar<String>()
@@ -52,7 +52,7 @@ class Outer<T> {
y = noParameters()
y().foo().a() checkType { _<A<T, F, Any, Double, Short, Long>>() }
y().bar() <!INAPPLICABLE_CANDIDATE!>checkType<!> { _<A<T, F, Any, Double, Short, Char>>() }
y().bar() <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<A<T, F, Any, Double, Short, Char>>() }
}
}
}
@@ -15,5 +15,5 @@ class Derived : BaseDerived2<Int>() {
fun foo() {
Derived().foo() checkType { _<Outer<Int, String>.Inner<Char>>() }
Derived().baz() <!INAPPLICABLE_CANDIDATE!>checkType<!> { _<Map<Char, Int>>() }
Derived().baz() <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<Map<Char, Int>>() }
}
@@ -32,5 +32,5 @@ fun foo() {
val csIt: Iterator<CharSequence> = A<String>().iterator()
commonSupertype(A<String>().iterator(), A<Int>().iterator()).checkType { <!INAPPLICABLE_CANDIDATE!>_<!><A<out Any>.MyIt>() }
commonSupertype(A<String>().iterator(), A<Int>().iterator()).checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><A<out Any>.MyIt>() }
}
@@ -5,7 +5,7 @@ class Outer<T> {
inner class Inner
fun foo(x: Outer<String>.Inner, y: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Outer<!>.Inner, z: Inner) {
var inner = Inner()
x.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Inner>() }
x.checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Inner>() }
x.checkType { _<Outer<String>.Inner>() }
z.checkType { _<Inner>() }
z.checkType { _<Outer<T>.Inner>() }
@@ -1,46 +0,0 @@
// !CHECK_TYPE
// Incorrect "type mismatch" error for generic extension safe call (required not-null, found nullable)
// FILE: B.java
public class B<T> {
public String gav() {
return "";
}
public static <T> B<T> create() {
return new B();
}
}
// FILE: A.kt
class A<T> {
fun gav() = ""
}
fun <R> foo(x: R) = x
fun <T> A<T>.bar() = ""
fun <T> B<T>.bar() = ""
fun foo(l: A<String>?) {
// No errors should be here
foo(l?.bar()) checkType { _<String?>() }
foo(l?.gav()) checkType { _<String?>() }
if (l != null) {
foo(l<!UNNECESSARY_SAFE_CALL!>?.<!>bar()) checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
foo(l<!UNNECESSARY_SAFE_CALL!>?.<!>gav()) checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
}
}
fun fooNotNull(l: A<String>) {
// No errors should be here
foo(l<!UNNECESSARY_SAFE_CALL!>?.<!>bar()) checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
foo(l<!UNNECESSARY_SAFE_CALL!>?.<!>gav()) checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
}
fun bar() {
val l = B.create<String>()
foo(l?.bar()) checkType { _<String?>() }
foo(l?.gav()) checkType { _<String?>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
// Incorrect "type mismatch" error for generic extension safe call (required not-null, found nullable)
@@ -15,5 +15,5 @@ fun <T> test(a: T) where T : B, T : C {
a.foo = ""
a.foo = null
a.foo.checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
a.foo.checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><String>() }
}
@@ -13,6 +13,6 @@ fun <F : String?> bar(x: F) {
foo1<<!UPPER_BOUND_VIOLATED!>F<!>>(<!ARGUMENT_TYPE_MISMATCH!>x<!>)
x<!UNSAFE_CALL!>.<!>foo2()
x.<!INAPPLICABLE_CANDIDATE!>foo2<!><F>()
x.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>foo2<!><F>()
}
@@ -1,17 +0,0 @@
class A<T> {
fun T.foo() {}
fun Out<T>.bar() {}
}
class Out<out E>
fun test(x: A<out CharSequence>, y: Out<CharSequence>) {
with(x) {
// TODO: this diagnostic could be replaced with TYPE_MISMATCH_DUE_TO_TYPE_PROJECTION
"".<!INAPPLICABLE_CANDIDATE!>foo<!>()
y.<!INAPPLICABLE_CANDIDATE!>bar<!>()
with(y) {
<!INAPPLICABLE_CANDIDATE!>bar<!>()
}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class A<T> {
fun T.foo() {}
fun Out<T>.bar() {}
@@ -10,5 +10,5 @@ fun main() {
val c : ListOfLists<*> = b
val d : ArrayList<ArrayList<*>> = <!INITIALIZER_TYPE_MISMATCH!>c.x<!>
c.x checkType { <!INAPPLICABLE_CANDIDATE!>_<!><ArrayList<out ArrayList<*>>>() }
c.x checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><ArrayList<out ArrayList<*>>>() }
}
@@ -9,10 +9,10 @@ public class Clazz<T> {
// FILE: main.kt
fun test(clazz: Clazz<*>) {
clazz.t checkType { _<Any?>() }
clazz.getSuperClass() checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Clazz<*>?>() }
clazz.getSuperClass() checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Clazz<*>?>() }
clazz.getSuperClass().t checkType { _<Any?>() }
clazz.superClass checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Clazz<*>?>() }
clazz.superClass checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Clazz<*>?>() }
clazz.superClass.t checkType { _<Any?>() }
// See KT-9294
@@ -12,9 +12,9 @@ class Inv2<T : Inv2<in T>>(val x: T)
fun main(a: A<*>, j: JavaClass<*>, i2: Inv2<*>) {
// Probably it's too restrictive to suppose star projection type here as Any?,
// but looks like we can refine it later
a.foo() checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Any?>() }
j.foo() checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Any?>() }
i2.x checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Any?>() }
a.foo() checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Any?>() }
j.foo() checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Any?>() }
i2.x checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Any?>() }
j.bar(<!ARGUMENT_TYPE_MISMATCH!>1<!>, <!ARGUMENT_TYPE_MISMATCH!>2<!>, <!ARGUMENT_TYPE_MISMATCH!>Any()<!>)
j.bar(null)