[FIR] Report INAPPLICABLE_CANDIDATE or more specific diagnostic for callable references
... instead of just UNRESOLVED_REFERENCE when something went wrong during resolution. #KT-59401 related
This commit is contained in:
committed by
Space Team
parent
6b7eeec181
commit
d91000e39c
Vendored
+2
-2
@@ -3,12 +3,12 @@ fun foo(x: String = "O"): String = x
|
||||
fun bar(x: String = "K"): String = x
|
||||
|
||||
fun dump(dumpStrategy: String) {
|
||||
val k0: kotlin.reflect.KFunction0<String> = returnAdapter(::<!UNRESOLVED_REFERENCE!>foo<!>) // Error: ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE
|
||||
val k0: kotlin.reflect.KFunction0<String> = returnAdapter(::<!INAPPLICABLE_CANDIDATE!>foo<!>) // Error: ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE
|
||||
val k1: kotlin.reflect.KFunction0<String> = <!INITIALIZER_TYPE_MISMATCH!>::foo<!>
|
||||
// Should be error here, too
|
||||
val k2: kotlin.reflect.KFunction0<String> = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>if (dumpStrategy == "KotlinLike") ::foo else ::bar<!>
|
||||
|
||||
val f0: Function0<String> = returnAdapter(::<!UNRESOLVED_REFERENCE!>foo<!>)
|
||||
val f0: Function0<String> = returnAdapter(::<!INAPPLICABLE_CANDIDATE!>foo<!>)
|
||||
val f1: Function0<String> = ::foo
|
||||
val f2: Function0<String> = if (dumpStrategy == "KotlinLike") ::foo else ::bar
|
||||
}
|
||||
|
||||
Vendored
+5
-5
@@ -6,10 +6,10 @@ public interface J {
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun f1(x: Int?): Any = x::<!UNRESOLVED_REFERENCE!>hashCode<!>
|
||||
fun <T> f2(t: T): Any = t::<!UNRESOLVED_REFERENCE!>hashCode<!>
|
||||
fun <S : String?> f3(s: S): Any = s::<!UNRESOLVED_REFERENCE!>hashCode<!>
|
||||
fun <U : Any> f4(u: U?): Any = u::<!UNRESOLVED_REFERENCE!>hashCode<!>
|
||||
fun f5(c: List<*>): Any = c[0]::<!UNRESOLVED_REFERENCE!>hashCode<!>
|
||||
fun f1(x: Int?): Any = x::<!UNSAFE_CALL!>hashCode<!>
|
||||
fun <T> f2(t: T): Any = t::<!UNSAFE_CALL!>hashCode<!>
|
||||
fun <S : String?> f3(s: S): Any = s::<!UNSAFE_CALL!>hashCode<!>
|
||||
fun <U : Any> f4(u: U?): Any = u::<!UNSAFE_CALL!>hashCode<!>
|
||||
fun f5(c: List<*>): Any = c[0]::<!UNSAFE_CALL!>hashCode<!>
|
||||
|
||||
fun f6(j: J): Any = j.platformString()::hashCode
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ class Foo<out T>(name: T) {
|
||||
val ok2 = this@Foo::prop
|
||||
val ok3 = object { val y: Any = this@Foo::prop }
|
||||
|
||||
val fail1 = Foo(prop)::<!UNRESOLVED_REFERENCE!>prop<!>
|
||||
val fail1 = Foo(prop)::<!INVISIBLE_REFERENCE!>prop<!>
|
||||
}
|
||||
|
||||
fun testFunc() {
|
||||
@@ -17,7 +17,7 @@ class Foo<out T>(name: T) {
|
||||
val ok2 = this@Foo::func
|
||||
val ok3 = object { val y: Any = this@Foo::func }
|
||||
|
||||
val fail1 = Foo(prop)::<!UNRESOLVED_REFERENCE!>func<!>
|
||||
val fail1 = Foo(prop)::<!INVISIBLE_REFERENCE!>func<!>
|
||||
}
|
||||
|
||||
private fun func(t: T): T = t
|
||||
|
||||
Vendored
+3
-3
@@ -19,9 +19,9 @@ class Test {
|
||||
|
||||
fun <T> List<T>.testCallable1(): () -> Unit = a::foo
|
||||
fun <T> List<T>.testCallable1a(): () -> Unit = <!EXPLICIT_TYPE_ARGUMENTS_IN_PROPERTY_ACCESS!>a<!><T>::foo
|
||||
fun <T> List<T>.testCallable2(): () -> Unit = b?::<!UNRESOLVED_REFERENCE!>foo<!>
|
||||
fun <T> List<T>.testCallable3(): () -> Unit = <!EXPLICIT_TYPE_ARGUMENTS_IN_PROPERTY_ACCESS!>b<!><T, Any>::<!UNRESOLVED_REFERENCE!>foo<!>
|
||||
fun <T> List<T>.testCallable4(): () -> Unit = <!EXPLICIT_TYPE_ARGUMENTS_IN_PROPERTY_ACCESS!>b<!><T>?::<!UNRESOLVED_REFERENCE!>foo<!>
|
||||
fun <T> List<T>.testCallable2(): () -> Unit = b?::<!UNSAFE_CALL!>foo<!>
|
||||
fun <T> List<T>.testCallable3(): () -> Unit = <!EXPLICIT_TYPE_ARGUMENTS_IN_PROPERTY_ACCESS!>b<!><T, Any>::<!UNSAFE_CALL!>foo<!>
|
||||
fun <T> List<T>.testCallable4(): () -> Unit = <!EXPLICIT_TYPE_ARGUMENTS_IN_PROPERTY_ACCESS!>b<!><T>?::<!UNSAFE_CALL!>foo<!>
|
||||
|
||||
fun <T> List<T>.testClassLiteral1() = a::class
|
||||
fun <T> List<T>.testClassLiteral1a() = <!EXPLICIT_TYPE_ARGUMENTS_IN_PROPERTY_ACCESS!>a<!><T>::class
|
||||
|
||||
Vendored
+1
-1
@@ -4,4 +4,4 @@ package test
|
||||
fun nullableFun(): Int? = null
|
||||
fun Int.foo() {}
|
||||
|
||||
val test1 = nullableFun()?::<!UNRESOLVED_REFERENCE!>foo<!>
|
||||
val test1 = nullableFun()?::<!UNSAFE_CALL!>foo<!>
|
||||
|
||||
Vendored
+1
-1
@@ -18,6 +18,6 @@ fun <K, V> B<K>.star(p: KProperty1<*, V>): B<V> = TODO()
|
||||
fun <R : A> B<R>.test(){
|
||||
foo(A::bla)
|
||||
bar(A::bla)
|
||||
baz(A::<!UNRESOLVED_REFERENCE!>bla<!>)
|
||||
baz(A::<!INAPPLICABLE_CANDIDATE!>bla<!>)
|
||||
star(A::bla)
|
||||
}
|
||||
|
||||
+1
-1
@@ -14,5 +14,5 @@ fun <K, V> B<K>.foo(p: KProperty1<K, V>) {}
|
||||
class C : A
|
||||
|
||||
fun <R : A> B<R>.test(){
|
||||
foo(C::<!UNRESOLVED_REFERENCE!>bla<!>)
|
||||
foo(C::<!INAPPLICABLE_CANDIDATE!>bla<!>)
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -7,6 +7,6 @@ fun <T> takeIt(x: T, f: SubFunction) {}
|
||||
fun cr() {}
|
||||
|
||||
fun test() {
|
||||
takeIt(42, ::<!UNRESOLVED_REFERENCE!>cr<!>)
|
||||
takeIt(42, ::<!INAPPLICABLE_CANDIDATE!>cr<!>)
|
||||
takeIt(42, <!ARGUMENT_TYPE_MISMATCH!>{ }<!>)
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -8,5 +8,5 @@ fun main() {
|
||||
::<!UNRESOLVED_REFERENCE!>A<!>
|
||||
::<!CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS!>B<!>
|
||||
::<!CALLABLE_REFERENCE_TO_ANNOTATION_CONSTRUCTOR!>C<!> // KT-3465
|
||||
::<!UNRESOLVED_REFERENCE!>D<!>
|
||||
::<!INVISIBLE_REFERENCE!>D<!>
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -25,7 +25,7 @@ class A {
|
||||
|
||||
expectFunction0Unit(::foo)
|
||||
expectFunction0String(::foo)
|
||||
expectFunction1Unit(::<!UNRESOLVED_REFERENCE!>foo<!>)
|
||||
expectFunction1String(::<!UNRESOLVED_REFERENCE!>foo<!>)
|
||||
expectFunction1Unit(::<!INAPPLICABLE_CANDIDATE!>foo<!>)
|
||||
expectFunction1String(::<!INAPPLICABLE_CANDIDATE!>foo<!>)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -16,14 +16,14 @@ fun <T> bar(s: T) {}
|
||||
fun <T> complex(t: T, f: (T) -> Unit) {}
|
||||
|
||||
fun test1() {
|
||||
foo(1, A::<!UNRESOLVED_REFERENCE!>invokeLater<!>) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE
|
||||
foo(1, A::<!INAPPLICABLE_CANDIDATE!>invokeLater<!>) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE
|
||||
foo(1, ::bar)
|
||||
|
||||
complex(1, ::bar)
|
||||
}
|
||||
|
||||
fun <R> test2(x: R) {
|
||||
foo(x, A::<!UNRESOLVED_REFERENCE!>invokeLater<!>) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE
|
||||
foo(x, A::<!INAPPLICABLE_CANDIDATE!>invokeLater<!>) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE
|
||||
foo(x, ::bar)
|
||||
|
||||
complex(x, ::bar)
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ fun <T> Wrapper<T>.baz(transform: (T) -> Unit): T = TODO()
|
||||
|
||||
fun test() {
|
||||
takeFun<String>(::foo)
|
||||
takeFun<String>(::<!UNRESOLVED_REFERENCE!>fooInt<!>)
|
||||
takeFun<String>(::<!INAPPLICABLE_CANDIDATE!>fooInt<!>)
|
||||
|
||||
callFun<String, Wrapper<String>>(::createWrapper)
|
||||
callFun<Int, Wrapper<Number>>(::createWrapper)
|
||||
|
||||
Vendored
+2
-2
@@ -22,8 +22,8 @@ fun test1() {
|
||||
fun <T> test2() {
|
||||
bar<Wrapper, Int, String>(Wrapper::fooReturnString).checkType { _<Tripple<Wrapper, Int, String>>() }
|
||||
bar<Wrapper, T, String>(Wrapper::fooReturnString).checkType { _<Tripple<Wrapper, T, String>>() }
|
||||
bar<Wrapper, T, T>(Wrapper::<!UNRESOLVED_REFERENCE!>fooReturnString<!>)
|
||||
bar<Wrapper, Int, Int>(Wrapper::<!UNRESOLVED_REFERENCE!>fooReturnString<!>)
|
||||
bar<Wrapper, T, T>(Wrapper::<!INAPPLICABLE_CANDIDATE!>fooReturnString<!>)
|
||||
bar<Wrapper, Int, Int>(Wrapper::<!INAPPLICABLE_CANDIDATE!>fooReturnString<!>)
|
||||
|
||||
bar<Wrapper, Int, T>(Wrapper::fooTakeInt).checkType { _<Tripple<Wrapper, Int, T>>() }
|
||||
bar<Wrapper, Int, String>(Wrapper::fooTakeInt).checkType { _<Tripple<Wrapper, Int, String>>() }
|
||||
|
||||
Vendored
+1
-1
@@ -4,7 +4,7 @@ fun foo(vararg ints: Int) {}
|
||||
fun test(i: IntArray) {
|
||||
myLet(i, ::foo)
|
||||
myLet(::foo)
|
||||
myLet<Int>(::<!UNRESOLVED_REFERENCE!>foo<!>)
|
||||
myLet<Int>(::<!INAPPLICABLE_CANDIDATE!>foo<!>)
|
||||
myLet<IntArray>(::foo)
|
||||
myLetExplicit1(::foo)
|
||||
myLetExplicit2(::foo)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fun box(): String {
|
||||
if (true) X::<!UNRESOLVED_REFERENCE!>y<!> else null
|
||||
if (true) X::<!INVISIBLE_REFERENCE!>y<!> else null
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -15,11 +15,11 @@ class A {
|
||||
|
||||
fun test() {
|
||||
String::<!EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED!>ext<!>
|
||||
Obj::<!UNRESOLVED_REFERENCE!>ext<!>
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>Obj::ext<!>
|
||||
|
||||
String::<!EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED!>ext2<!>
|
||||
A.Companion::<!UNRESOLVED_REFERENCE!>ext2<!>
|
||||
A::<!UNRESOLVED_REFERENCE!>ext2<!>
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>A.Companion::ext2<!>
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>A::ext2<!>
|
||||
|
||||
A::<!UNRESOLVED_REFERENCE!>foo<!>
|
||||
A::<!UNRESOLVED_REFERENCE!>bar<!>
|
||||
|
||||
+2
-2
@@ -21,6 +21,6 @@ fun test() {
|
||||
val pubMutRef: KMutableProperty1<JavaClass, Long> = JavaClass::publicMutable
|
||||
val protFinRef: KProperty1<JavaClass, Double> = JavaClass::protectedFinal
|
||||
val protMutRef: KMutableProperty1<JavaClass, Char> = JavaClass::protectedMutable
|
||||
val privFinRef: KProperty1<JavaClass, String?> = JavaClass::<!UNRESOLVED_REFERENCE!>privateFinal<!>
|
||||
val privMutRef: KMutableProperty1<JavaClass, Any?> = JavaClass::<!UNRESOLVED_REFERENCE!>privateMutable<!>
|
||||
val privFinRef: KProperty1<JavaClass, String?> = JavaClass::<!INVISIBLE_REFERENCE!>privateFinal<!>
|
||||
val privMutRef: KMutableProperty1<JavaClass, Any?> = JavaClass::<!INVISIBLE_REFERENCE!>privateMutable<!>
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -23,6 +23,6 @@ fun test() {
|
||||
val pubMutRef: KMutableProperty0<Any?> = ::publicMutable
|
||||
val protFinRef: KProperty<Double> = ::protectedFinal
|
||||
val protMutRef: KMutableProperty<Char> = ::protectedMutable
|
||||
val privFinRef: KProperty<JavaClass?> = ::<!UNRESOLVED_REFERENCE!>privateFinal<!>
|
||||
val privMutRef: KMutableProperty<Throwable?> = ::<!UNRESOLVED_REFERENCE!>privateMutable<!>
|
||||
val privFinRef: KProperty<JavaClass?> = ::<!INVISIBLE_REFERENCE!>privateFinal<!>
|
||||
val privMutRef: KMutableProperty<Throwable?> = ::<!INVISIBLE_REFERENCE!>privateMutable<!>
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,6 +22,6 @@ object Local {
|
||||
fun baz(x: Int, y: Int = 0): Int = 0
|
||||
|
||||
fun test() {
|
||||
bar(::<!UNRESOLVED_REFERENCE!>baz<!>)
|
||||
bar(::<!INAPPLICABLE_CANDIDATE!>baz<!>)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,6 +22,6 @@ object Local {
|
||||
fun baz(x: Int, y: Int = 0): Int = 0
|
||||
|
||||
fun test() {
|
||||
bar(::<!UNRESOLVED_REFERENCE!>baz<!>)
|
||||
bar(::<!INAPPLICABLE_CANDIDATE!>baz<!>)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,4 +5,4 @@ import kotlin.reflect.KProperty0
|
||||
object A
|
||||
|
||||
fun <TProperty> property0(property: KProperty0<TProperty>) = A
|
||||
val <K> K.key get() : A = property0(Map.Entry<K, *>::<!UNRESOLVED_REFERENCE!>key<!>) // should be forbidden
|
||||
val <K> K.key get() : A = property0(Map.Entry<K, *>::<!INAPPLICABLE_CANDIDATE!>key<!>) // should be forbidden
|
||||
|
||||
+2
-2
@@ -10,6 +10,6 @@ fun <T> baz(e: T, f: (T) -> Unit) {}
|
||||
|
||||
fun test(a: A, b: B) {
|
||||
// Note that diagnostic is always on callable references as they are resolved after simple arguments
|
||||
baz(a, ::<!UNRESOLVED_REFERENCE!>fooB<!>)
|
||||
bar(::<!UNRESOLVED_REFERENCE!>fooB<!>, a)
|
||||
baz(a, ::<!INAPPLICABLE_CANDIDATE!>fooB<!>)
|
||||
bar(::<!INAPPLICABLE_CANDIDATE!>fooB<!>, a)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user