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
|
||||
}
|
||||
+3
-3
@@ -58,7 +58,7 @@ FILE fqName:<root> fileName:/funWithDefaultParametersAsKCallableStar.kt
|
||||
FUN name:testDefaultsOnlyStar visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||
BLOCK_BODY
|
||||
CALL 'public final fun useKCallableStar (fn: kotlin.reflect.KCallable<*>): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
fn: FUNCTION_REFERENCE 'public final fun defaultsOnly (x: kotlin.String): kotlin.Int declared in <root>' type=kotlin.reflect.KFunction0<kotlin.Int> origin=null reflectionTarget=<same>
|
||||
fn: FUNCTION_REFERENCE 'public final fun defaultsOnly (x: kotlin.String): kotlin.Int declared in <root>' type=kotlin.reflect.KFunction1<kotlin.String, kotlin.Int> origin=null reflectionTarget=<same>
|
||||
FUN name:testRegularAndDefaultsStar visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||
BLOCK_BODY
|
||||
CALL 'public final fun useKCallableStar (fn: kotlin.reflect.KCallable<*>): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
@@ -66,8 +66,8 @@ FILE fqName:<root> fileName:/funWithDefaultParametersAsKCallableStar.kt
|
||||
FUN name:testVarargsStar visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||
BLOCK_BODY
|
||||
CALL 'public final fun useKCallableStar (fn: kotlin.reflect.KCallable<*>): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
fn: FUNCTION_REFERENCE 'public final fun varargs (vararg xs: kotlin.String): kotlin.Int declared in <root>' type=kotlin.reflect.KFunction0<kotlin.Int> origin=null reflectionTarget=<same>
|
||||
fn: FUNCTION_REFERENCE 'public final fun varargs (vararg xs: kotlin.String): kotlin.Int declared in <root>' type=kotlin.reflect.KFunction1<kotlin.Array<out kotlin.String>, kotlin.Int> origin=null reflectionTarget=<same>
|
||||
FUN name:testCtorStar visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||
BLOCK_BODY
|
||||
CALL 'public final fun useKCallableStar (fn: kotlin.reflect.KCallable<*>): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
fn: FUNCTION_REFERENCE 'public constructor <init> (x: kotlin.String) [primary] declared in <root>.C' type=kotlin.reflect.KFunction0<<root>.C> origin=null reflectionTarget=<same>
|
||||
fn: FUNCTION_REFERENCE 'public constructor <init> (x: kotlin.String) [primary] declared in <root>.C' type=kotlin.reflect.KFunction1<kotlin.String, <root>.C> origin=null reflectionTarget=<same>
|
||||
|
||||
Reference in New Issue
Block a user