[FIR] Improve diagnostic reporting & don't use error symbol for candidate if possible

Also introduce few new diagnostics:
- NONE_APPLICABLE more many inapplicable candidates
- HIDDEN for visible candidates
This commit is contained in:
Dmitriy Novozhilov
2020-07-22 16:40:14 +03:00
committed by Mikhail Glukhikh
parent 5c0528b61e
commit f283f2db43
365 changed files with 1400 additions and 1451 deletions
@@ -1,18 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun interface IFoo {
fun foo(i: Int)
}
fun interface IFoo2 : IFoo
object A
operator fun A.get(i: IFoo) = 1
operator fun A.set(i: IFoo, newValue: Int) {}
fun withVararg(vararg xs: Int) = 42
fun test1() {
<!UNRESOLVED_REFERENCE!><!INAPPLICABLE_CANDIDATE!>A[::withVararg]<!> += 1<!>
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun interface IFoo {
@@ -19,6 +19,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)
<!INAPPLICABLE_CANDIDATE!>baz<!>(A::bla)
<!INAPPLICABLE_CANDIDATE!>baz<!>(<!UNRESOLVED_REFERENCE!>A::bla<!>)
star(A::bla)
}
}
@@ -15,5 +15,5 @@ fun <K, V> B<K>.foo(p: KProperty1<K, V>) {}
class C : A
fun <R : A> B<R>.test(){
<!INAPPLICABLE_CANDIDATE!>foo<!>(C::bla)
<!INAPPLICABLE_CANDIDATE!>foo<!>(<!UNRESOLVED_REFERENCE!>C::bla<!>)
}
@@ -8,6 +8,6 @@ fun <T> takeIt(x: T, f: SubFunction) {}
fun cr() {}
fun test() {
<!INAPPLICABLE_CANDIDATE!>takeIt<!>(42, ::cr)
<!INAPPLICABLE_CANDIDATE!>takeIt<!>(42, <!UNRESOLVED_REFERENCE!>::cr<!>)
<!INAPPLICABLE_CANDIDATE!>takeIt<!>(42, { })
}
@@ -1,19 +0,0 @@
// !WITH_NEW_INFERENCE
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.*
interface A
interface B : A
fun A.foo() {}
fun take(f: (A) -> Unit) {}
fun take(f: () -> Unit) {}
fun test() {
B::foo checkType { _<KFunction1<B, Unit>>() }
<!INAPPLICABLE_CANDIDATE!>take<!>(B::foo)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !WITH_NEW_INFERENCE
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -25,7 +25,7 @@ class A {
expectFunction0Unit(::foo)
expectFunction0String(::foo)
<!INAPPLICABLE_CANDIDATE!>expectFunction1Unit<!>(::foo)
<!INAPPLICABLE_CANDIDATE!>expectFunction1String<!>(::foo)
<!INAPPLICABLE_CANDIDATE!>expectFunction1Unit<!>(<!UNRESOLVED_REFERENCE!>::foo<!>)
<!INAPPLICABLE_CANDIDATE!>expectFunction1String<!>(<!UNRESOLVED_REFERENCE!>::foo<!>)
}
}
@@ -16,15 +16,15 @@ fun <T> bar(s: T) {}
fun <T> complex(t: T, f: (T) -> Unit) {}
fun test1() {
<!INAPPLICABLE_CANDIDATE!>foo<!>(1, A::invokeLater) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE
<!INAPPLICABLE_CANDIDATE!>foo<!>(1, <!UNRESOLVED_REFERENCE!>A::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) {
<!INAPPLICABLE_CANDIDATE!>foo<!>(x, A::invokeLater) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE
<!INAPPLICABLE_CANDIDATE!>foo<!>(x, <!UNRESOLVED_REFERENCE!>A::invokeLater<!>) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE
foo(x, ::bar)
complex(x, ::bar)
}
}
@@ -14,7 +14,7 @@ fun <T> Wrapper<T>.baz(transform: (T) -> Unit): T = TODO()
fun test() {
takeFun<String>(::foo)
<!INAPPLICABLE_CANDIDATE!>takeFun<!><String>(::fooInt)
<!INAPPLICABLE_CANDIDATE!>takeFun<!><String>(<!UNRESOLVED_REFERENCE!>::fooInt<!>)
callFun<String, Wrapper<String>>(::createWrapper)
callFun<Int, Wrapper<Number>>(::createWrapper)
@@ -23,9 +23,9 @@ 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>>() }
<!INAPPLICABLE_CANDIDATE!>bar<!><Wrapper, T, T>(Wrapper::fooReturnString)
<!INAPPLICABLE_CANDIDATE!>bar<!><Wrapper, Int, Int>(Wrapper::fooReturnString)
<!INAPPLICABLE_CANDIDATE!>bar<!><Wrapper, T, T>(<!UNRESOLVED_REFERENCE!>Wrapper::fooReturnString<!>)
<!INAPPLICABLE_CANDIDATE!>bar<!><Wrapper, Int, Int>(<!UNRESOLVED_REFERENCE!>Wrapper::fooReturnString<!>)
bar<Wrapper, Int, T>(Wrapper::fooTakeInt).checkType { _<Tripple<Wrapper, Int, T>>() }
bar<Wrapper, Int, String>(Wrapper::fooTakeInt).checkType { _<Tripple<Wrapper, Int, String>>() }
}
}
@@ -5,9 +5,9 @@ fun foo(vararg ints: Int) {}
fun test(i: IntArray) {
myLet(i, ::foo)
myLet(::foo)
<!INAPPLICABLE_CANDIDATE!>myLet<!><Int>(::foo)
<!INAPPLICABLE_CANDIDATE!>myLet<!><Int>(<!UNRESOLVED_REFERENCE!>::foo<!>)
myLet<IntArray>(::foo)
<!INAPPLICABLE_CANDIDATE!>myLetExplicit1<!>(::foo)
<!INAPPLICABLE_CANDIDATE!>myLetExplicit1<!>(<!UNRESOLVED_REFERENCE!>::foo<!>)
myLetExplicit2(::foo)
}
@@ -12,7 +12,7 @@ fun allOfTheAbove(f: (A) -> Unit): Any = f
fun test() {
coercionToUnit(A::foo)
<!INAPPLICABLE_CANDIDATE!>varargToElement<!>(A::foo)
<!INAPPLICABLE_CANDIDATE!>varargToElement<!>(<!UNRESOLVED_REFERENCE!>A::foo<!>)
defaultAndVararg(A::foo)
allOfTheAbove(A::foo)
}
}
@@ -11,9 +11,9 @@ class Foo {
}
fun foo() {
<!INAPPLICABLE_CANDIDATE!>installRoute<!><Any>(::route)
<!NONE_APPLICABLE!>installRoute<!><Any>(::route)
}
}
fun route(s: String): Any? = null
fun route(s: String): Any? = null
@@ -6,4 +6,4 @@ import kotlin.reflect.KProperty0
object A
fun <TProperty> property0(property: KProperty0<TProperty>) = A
val <K> K.key get() : A = <!INAPPLICABLE_CANDIDATE!>property0<!>(Map.Entry<K, *>::key) // should be forbidden
val <K> K.key get() : A = <!INAPPLICABLE_CANDIDATE!>property0<!>(<!UNRESOLVED_REFERENCE!>Map.Entry<K, *>::key<!>) // should be forbidden
@@ -11,6 +11,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
<!INAPPLICABLE_CANDIDATE!>baz<!>(a, ::fooB)
<!INAPPLICABLE_CANDIDATE!>bar<!>(::fooB, a)
}
<!INAPPLICABLE_CANDIDATE!>baz<!>(a, <!UNRESOLVED_REFERENCE!>::fooB<!>)
<!INAPPLICABLE_CANDIDATE!>bar<!>(<!UNRESOLVED_REFERENCE!>::fooB<!>, a)
}
@@ -3,8 +3,8 @@
// WITH_RUNTIME
fun <T> List<Option<T>>.flatten(): List<T> = <!AMBIGUITY!>flatMap<!> { <!UNRESOLVED_REFERENCE!>it<!>.<!INAPPLICABLE_CANDIDATE!>fold<!>(::emptyList, <!UNRESOLVED_REFERENCE!>::listOf<!>) }
fun <T> List<Option<T>>.flatten(): List<T> = <!AMBIGUITY!>flatMap<!> { <!UNRESOLVED_REFERENCE!>it<!>.<!NONE_APPLICABLE!>fold<!>(::emptyList, <!UNRESOLVED_REFERENCE!>::listOf<!>) }
class Option<out T> {
fun <R> fold(ifEmpty: () -> R, ifSome: (T) -> R): R = TODO()
}
}