[FIR] Implement ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE diagnostic

#KT-59401 Fixed
This commit is contained in:
Kirill Rakhman
2023-11-03 15:27:36 +01:00
committed by Space Team
parent d91000e39c
commit 789f886d3c
18 changed files with 104 additions and 92 deletions
@@ -1,27 +0,0 @@
// !LANGUAGE: -AdaptedCallableReferenceAgainstReflectiveType +DisableCompatibilityModeForNewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KFunction1
fun foo(x: Int): Unit {} // (1)
fun bar(f: KFunction1<Int, Unit>) {}
fun test() {
bar(::foo) // OK, foo resolved to (1)
}
object Scope {
fun foo(x: Int, y: Int = 0): Int = 0 // (2)
fun test() {
bar(::foo) // Error and foo should be resolved to (2)
}
}
object Local {
fun baz(x: Int, y: Int = 0): Int = 0
fun test() {
bar(::<!INAPPLICABLE_CANDIDATE!>baz<!>)
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: -AdaptedCallableReferenceAgainstReflectiveType +DisableCompatibilityModeForNewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -15,6 +16,7 @@ object Scope {
fun test() {
bar(<!ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE!>::foo<!>) // Error and foo should be resolved to (2)
bar(<!ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE!>Scope::foo<!>) // Error and foo should be resolved to (2)
}
}
@@ -25,3 +27,11 @@ object Local {
bar(<!ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE!>::baz<!>)
}
}
object WrongType {
fun foo(x: String, y: Int = 0) {} // (3)
fun test() {
bar(::foo) // Should resolve to (1) because (3) has wrong type on top of being adapted
}
}
@@ -1,23 +0,0 @@
package
public fun bar(/*0*/ f: kotlin.reflect.KFunction1<kotlin.Int, kotlin.Unit>): kotlin.Unit
public fun foo(/*0*/ x: kotlin.Int): kotlin.Unit
public fun test(): kotlin.Unit
public object Local {
private constructor Local()
public final fun baz(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int = ...): kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun test(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public object Scope {
private constructor Scope()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int = ...): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun test(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -15,6 +15,7 @@ object Scope {
fun test() {
bar(::foo)
bar(<!ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE!>Scope::foo<!>)
}
}
@@ -22,6 +23,14 @@ object Local {
fun baz(x: Int, y: Int = 0): Int = 0
fun test() {
bar(::<!INAPPLICABLE_CANDIDATE!>baz<!>)
bar(<!ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE!>::baz<!>)
}
}
object WrongType {
fun foo(x: String, y: Int = 0) {} // (3)
fun test() {
bar(::foo) // Should resolve to (1) because (3) has wrong type on top of being adapted
}
}
@@ -15,6 +15,7 @@ object Scope {
fun test() {
bar(<!COMPATIBILITY_WARNING!>::foo<!>)
bar(<!ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE!>Scope::foo<!>)
}
}
@@ -25,3 +26,11 @@ object Local {
bar(<!ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE!>::baz<!>)
}
}
object WrongType {
fun foo(x: String, y: Int = 0) {} // (3)
fun test() {
bar(::foo) // Should resolve to (1) because (3) has wrong type on top of being adapted
}
}
@@ -1,23 +0,0 @@
package
public fun bar(/*0*/ f: kotlin.reflect.KFunction1<kotlin.Int, kotlin.Unit>): kotlin.Unit
public fun foo(/*0*/ x: kotlin.Int): kotlin.Unit
public fun test(): kotlin.Unit
public object Local {
private constructor Local()
public final fun baz(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int = ...): kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun test(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public object Scope {
private constructor Scope()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int = ...): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun test(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}