[FIR] Properly handle callable references which were resolved with error

This commit is contained in:
Dmitriy Novozhilov
2021-04-15 14:06:30 +03:00
parent 450fb5e915
commit e869f8091a
74 changed files with 377 additions and 312 deletions
@@ -3,7 +3,7 @@ fun foo(x: Int, y: Any) = x
fun foo(x: Any, y: Int) = y
fun main() {
::<!UNRESOLVED_REFERENCE!>foo<!>
::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>
val fooRef: (Int, Any) -> Unit = ::<!UNRESOLVED_REFERENCE!>foo<!>
}
@@ -6,5 +6,5 @@ object TestCallableReferences {
fun test0(): (String) -> String = TestCallableReferences::foo
fun <T> test1(): (List<T>) -> List<T> = TestCallableReferences::<!UNRESOLVED_REFERENCE!>foo<!>
fun <T> test1(): (List<T>) -> List<T> = TestCallableReferences::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>
}
@@ -1,7 +0,0 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION
val i: Int = 10
get() {
<!UNSUPPORTED!>::field<!>
return field
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_EXPRESSION
val i: Int = 10
@@ -22,7 +22,7 @@ fun B.foo(): Double = 0.0
fun call(a: Any) {}
fun testA(a: A) {
call(A::<!UNRESOLVED_REFERENCE!>foo<!>)
call(A::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>)
call(A.Companion::foo)
}
@@ -7,5 +7,5 @@ fun foo(y: String) {}
fun <T> bar(f: (T) -> Unit) {}
fun test() {
bar(::<!UNRESOLVED_REFERENCE!>foo<!>)
bar(::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>)
}
@@ -10,6 +10,6 @@ fun A.foo() = ""
class A {
fun main() {
bar(::<!UNRESOLVED_REFERENCE!>foo<!>) checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
bar(::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>) checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }
}
}
@@ -1,16 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun fun1() {}
fun fun1(x: Int) {}
val ref1 = ::<!UNRESOLVED_REFERENCE!>fun1<!>
fun fun2(vararg x: Int) {}
fun fun2(x: Int) {}
val ref2 = ::<!UNRESOLVED_REFERENCE!>fun2<!>
fun fun3(x0: Int, vararg xs: Int) {}
fun fun3(x0: String, vararg xs: String) {}
val ref3 = ::<!UNRESOLVED_REFERENCE!>fun3<!>
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun fun1() {}
@@ -3,7 +3,7 @@
fun foo() {}
fun foo(s: String) {}
val x1 = ::<!UNRESOLVED_REFERENCE!>foo<!>
val x1 = ::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>
val x2: () -> Unit = ::foo
val x3: (String) -> Unit = ::foo
val x4: (Int) -> Unit = ::<!UNRESOLVED_REFERENCE!>foo<!>
@@ -31,7 +31,7 @@ fun test() {
val t3 = bar(::baz)
t3
bar(::<!UNRESOLVED_REFERENCE!>foo<!>)
bar(::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>)
}
}
}
@@ -31,5 +31,5 @@ fun test() {
val a6 = foo(::singleA, ::singleB)
a6
foo(::<!UNRESOLVED_REFERENCE!>multiple<!>, ::<!UNRESOLVED_REFERENCE!>multiple<!>)
foo(::<!OVERLOAD_RESOLUTION_AMBIGUITY!>multiple<!>, ::<!OVERLOAD_RESOLUTION_AMBIGUITY!>multiple<!>)
}
@@ -9,7 +9,7 @@ fun IB.extFun(x: IA) {}
fun test() {
val extFun1 = IA::extFun
val extFun2 = IB::<!UNRESOLVED_REFERENCE!>extFun<!>
val extFun2 = IB::<!OVERLOAD_RESOLUTION_AMBIGUITY!>extFun<!>
}
fun testWithExpectedType() {
@@ -17,5 +17,5 @@ fun testWithExpectedType() {
val extFun_AA_B: IA.(IA) -> Unit = IB::<!UNRESOLVED_REFERENCE!>extFun<!>
val extFun_BB_A: IB.(IB) -> Unit = IA::extFun
val extFun_BA_B: IB.(IA) -> Unit = IB::extFun
val extFun_BB_B: IB.(IB) -> Unit = IB::<!UNRESOLVED_REFERENCE!>extFun<!>
val extFun_BB_B: IB.(IB) -> Unit = IB::<!OVERLOAD_RESOLUTION_AMBIGUITY!>extFun<!>
}
@@ -1,30 +0,0 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
import kotlin.reflect.KFunction1
open class A {
open fun bar() {}
fun bas() {}
}
class B: A() {
override fun bar() {}
fun bas(i: Int) {}
}
fun A.foo() {}
fun B.foo() {}
fun fas() {}
fun fas(i: Int = 1) {}
fun test() {
B::foo // todo KT-9601 Chose maximally specific function in callable reference
B::bar checkType { _<KFunction1<B, Unit>>() }
B::<!UNRESOLVED_REFERENCE!>bas<!>
::<!UNRESOLVED_REFERENCE!>fas<!>
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
import kotlin.reflect.KFunction1
@@ -1,10 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun foo() {}
fun foo(s: String) {}
fun bar(f: () -> Unit) = 1
fun bar(f: (String) -> Unit) = 2
val x1 = ::<!UNRESOLVED_REFERENCE!>foo<!> as () -> Unit
val x2 = bar(::<!UNRESOLVED_REFERENCE!>foo<!> as (String) -> Unit)
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun foo() {}
@@ -1,27 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER, -EXTENSION_SHADOWED_BY_MEMBER
import kotlin.reflect.*
fun <T> ofType(x: T): T = x
class A {
val foo: Int = 0
fun foo() {}
fun bar() {}
val bar: Int = 0
}
fun A.foo(): String = "A"
val x0 = A::<!UNRESOLVED_REFERENCE!>foo<!>
val x1 = ofType<(A) -> Unit>(A::foo)
val x2 = ofType<KProperty1<A, Int>>(A::foo)
val x3: KProperty1<A, Int> = A::foo
val x4: (A) -> String = A::foo
val y0 = A::<!UNRESOLVED_REFERENCE!>bar<!>
val y1 = ofType<(A) -> Unit>(A::bar)
val y2 = ofType<KProperty1<A, Int>>(A::bar)
val y3: KProperty1<A, Int> = A::bar
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER, -EXTENSION_SHADOWED_BY_MEMBER
import kotlin.reflect.*
@@ -22,7 +22,7 @@ val x1 = fn1(1, ::foo, ::foo)
val x2 = fn1(1, ::foo, ::bar)
val x3 = fn2(::bar, ::foo)
val x4 = <!OVERLOAD_RESOLUTION_AMBIGUITY!>fn2<!>(::<!UNRESOLVED_REFERENCE!>foo<!>, ::bar)
val x5 = <!OVERLOAD_RESOLUTION_AMBIGUITY!>fn2<!>(::<!UNRESOLVED_REFERENCE!>foo<!>, ::<!UNRESOLVED_REFERENCE!>foo<!>)
val x4 = <!OVERLOAD_RESOLUTION_AMBIGUITY!>fn2<!>(::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>, ::bar)
val x5 = <!OVERLOAD_RESOLUTION_AMBIGUITY!>fn2<!>(::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>, ::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>)
val x6 = fn3(1, ::qux)
@@ -1,8 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
fun a() {
val x = 10
foo(<!UNSUPPORTED!>::x<!>)
}
fun foo(a: Any) {}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
fun a() {
@@ -1,15 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
fun eat(value: Any) {}
fun test(param: String) {
val a = <!UNSUPPORTED!>::param<!>
val local = "local"
val b = <!UNSUPPORTED!>::local<!>
val lambda = { -> }
val g = <!UNSUPPORTED!>::lambda<!>
eat(<!UNSUPPORTED!>::param<!>)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
fun eat(value: Any) {}
@@ -9,6 +9,6 @@ class Foo {
fun main() {
val f = Foo()
val a: Int
<!VARIABLE_EXPECTED!>get()<!> = f.getValue(null, <!UNSUPPORTED!>::a<!>) // no exception after fix
<!VARIABLE_EXPECTED!>get()<!> = f.getValue(null, ::<!UNSUPPORTED!>a<!>) // no exception after fix
<!UNRESOLVED_REFERENCE!>print<!>(<!UNINITIALIZED_VARIABLE!>a<!>)
}
@@ -9,6 +9,6 @@ class Foo {
fun main(x: Int) {
val f = Foo()
val a: Int
<!VARIABLE_EXPECTED!>get()<!> = f.getValue(null, <!UNSUPPORTED!>::x<!>) // no exception after fix
<!VARIABLE_EXPECTED!>get()<!> = f.getValue(null, ::<!UNSUPPORTED!>x<!>) // no exception after fix
<!UNRESOLVED_REFERENCE!>print<!>(<!UNINITIALIZED_VARIABLE!>a<!>)
}
@@ -13,9 +13,9 @@ fun main() {
val x7 = <!UNRESOLVED_REFERENCE!>logger<!>::info<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>::<!UNRESOLVED_REFERENCE!>print<!>?::<!UNRESOLVED_REFERENCE!>print<!>
val x8 = <!UNRESOLVED_REFERENCE!>logger<!>?::info<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>::<!UNRESOLVED_REFERENCE!>print<!>?::<!UNRESOLVED_REFERENCE!>print<!>
val x9 = <!UNRESOLVED_REFERENCE!>logger<!>!!::<!UNRESOLVED_REFERENCE!>info<!>?::<!UNRESOLVED_REFERENCE!>print<!>?::<!UNRESOLVED_REFERENCE!>print<!>
val x10 = <!UNRESOLVED_REFERENCE!>logger<!>::info?::print<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>::<!UNRESOLVED_REFERENCE!>print<!>
val x11 = <!UNRESOLVED_REFERENCE!>logger<!>!!::info<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>::print<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>::<!UNRESOLVED_REFERENCE!>print<!>
val x12 = <!UNRESOLVED_REFERENCE!>logger<!>?::info<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>::print<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>::<!UNRESOLVED_REFERENCE!>print<!>
val x10 = <!UNRESOLVED_REFERENCE!>logger<!>::info?::<!UNRESOLVED_REFERENCE!>print<!><!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>::<!UNRESOLVED_REFERENCE!>print<!>
val x11 = <!UNRESOLVED_REFERENCE!>logger<!>!!::<!UNRESOLVED_REFERENCE!>info<!><!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>::<!UNRESOLVED_REFERENCE!>print<!><!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>::<!UNRESOLVED_REFERENCE!>print<!>
val x12 = <!UNRESOLVED_REFERENCE!>logger<!>?::info<!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>::<!UNRESOLVED_REFERENCE!>print<!><!NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>::<!UNRESOLVED_REFERENCE!>print<!>
val x13 = 42?::<!UNRESOLVED_REFERENCE!>unresolved<!>?::<!UNRESOLVED_REFERENCE!>print<!>
val x14 = <!UNRESOLVED_REFERENCE!>logger<!><!SYNTAX!>?!!::info?::print?::print<!>