Prohibit adapted reference resolve against reflective types
There are design questions about reflection for adapted references, so the current proposal is to prohibit reflection on them and support it properly later #KT-40406 Fixed
This commit is contained in:
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: -AdaptedCallableReferenceAgainstReflectiveType
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
import kotlin.reflect.KCallable
|
||||
|
||||
fun take(k: KCallable<*>) {}
|
||||
|
||||
fun foo(x: Int = 0) {}
|
||||
|
||||
fun test() {
|
||||
take(::foo)
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
public fun foo(/*0*/ x: kotlin.Int = ...): kotlin.Unit
|
||||
public fun take(/*0*/ k: kotlin.reflect.KCallable<*>): kotlin.Unit
|
||||
public fun test(): kotlin.Unit
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// !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(::baz)
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// !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(<!ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE!>::foo<!>) // Error and foo should be resolved to (2)
|
||||
}
|
||||
}
|
||||
|
||||
object Local {
|
||||
fun baz(x: Int, y: Int = 0): Int = 0
|
||||
|
||||
fun test() {
|
||||
bar(<!ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE!>::baz<!>)
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
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
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// !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)
|
||||
}
|
||||
|
||||
object Scope {
|
||||
fun foo(x: Int, y: Int = 0): Int = 0 // (2)
|
||||
|
||||
fun test() {
|
||||
bar(::foo)
|
||||
}
|
||||
}
|
||||
|
||||
object Local {
|
||||
fun baz(x: Int, y: Int = 0): Int = 0
|
||||
|
||||
fun test() {
|
||||
bar(::baz)
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// !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)
|
||||
}
|
||||
|
||||
object Scope {
|
||||
fun foo(x: Int, y: Int = 0): Int = 0 // (2)
|
||||
|
||||
fun test() {
|
||||
bar(<!COMPATIBILITY_WARNING!>::foo<!>)
|
||||
}
|
||||
}
|
||||
|
||||
object Local {
|
||||
fun baz(x: Int, y: Int = 0): Int = 0
|
||||
|
||||
fun test() {
|
||||
bar(<!ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE!>::baz<!>)
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user