Simplify function hierarchy in reflection
Get rid of all classes except kotlin.reflect.KFunction, which will be used to represent all kinds of simple functions. Lots of changes to test data are related to the fact that KFunction is not an extension function (as opposed to KMemberFunction and KExtensionFunction who were) and so a member or an extension function reference now requires all arguments be passed to it in the parentheses, including receivers. This is probably temporary until we support calling any function both as a free function and as an extension. In JS, functions and extension functions are not interchangeable, so tests on this behavior are removed until this is supported
This commit is contained in:
Vendored
+2
-2
@@ -5,5 +5,5 @@ open class A {
|
||||
}
|
||||
|
||||
fun test() {
|
||||
A.B.(A::foo)()
|
||||
}
|
||||
(A::foo)(A.B)
|
||||
}
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@ fun main() {
|
||||
val y = first.A::bar
|
||||
val z = A::baz
|
||||
|
||||
checkSubtype<KMemberFunction0<A, Unit>>(x)
|
||||
checkSubtype<KMemberFunction1<A, Int, Unit>>(y)
|
||||
checkSubtype<KMemberFunction0<A, String>>(z)
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
checkSubtype<KFunction2<A, Int, Unit>>(y)
|
||||
checkSubtype<KFunction1<A, String>>(z)
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -14,7 +14,7 @@ fun A.baz() {}
|
||||
|
||||
package other
|
||||
|
||||
import kotlin.reflect.KExtensionFunction0
|
||||
import kotlin.reflect.KFunction1
|
||||
|
||||
import first.A
|
||||
import first.foo
|
||||
@@ -24,5 +24,5 @@ fun main() {
|
||||
first.A::<!UNRESOLVED_REFERENCE!>bar<!>
|
||||
A::<!UNRESOLVED_REFERENCE!>baz<!>
|
||||
|
||||
checkSubtype<KExtensionFunction0<A, Unit>>(x)
|
||||
}
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
}
|
||||
|
||||
+3
-3
@@ -8,9 +8,9 @@ class A {
|
||||
val y = ::bar
|
||||
val z = ::baz
|
||||
|
||||
checkSubtype<KExtensionFunction0<A, Unit>>(x)
|
||||
checkSubtype<KExtensionFunction1<A, Int, Unit>>(y)
|
||||
checkSubtype<KExtensionFunction0<A, String>>(z)
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
checkSubtype<KFunction2<A, Int, Unit>>(y)
|
||||
checkSubtype<KFunction1<A, String>>(z)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -9,9 +9,9 @@ fun A.main() {
|
||||
val y = ::bar
|
||||
val z = ::baz
|
||||
|
||||
checkSubtype<KExtensionFunction0<A, Unit>>(x)
|
||||
checkSubtype<KExtensionFunction1<A, Int, Unit>>(y)
|
||||
checkSubtype<KExtensionFunction0<A, String>>(z)
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
checkSubtype<KFunction2<A, Int, Unit>>(y)
|
||||
checkSubtype<KFunction1<A, String>>(z)
|
||||
}
|
||||
|
||||
fun A.foo() {}
|
||||
|
||||
Vendored
+3
-3
@@ -10,9 +10,9 @@ class A {
|
||||
val y = ::bar
|
||||
val z = ::baz
|
||||
|
||||
checkSubtype<KExtensionFunction0<A, Unit>>(x)
|
||||
checkSubtype<KExtensionFunction1<A, Int, Unit>>(y)
|
||||
checkSubtype<KExtensionFunction0<A, String>>(z)
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
checkSubtype<KFunction2<A, Int, Unit>>(y)
|
||||
checkSubtype<KFunction1<A, String>>(z)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -13,11 +13,11 @@ fun main() {
|
||||
val y = A::bar
|
||||
val z = A::baz
|
||||
|
||||
checkSubtype<KExtensionFunction0<A, Unit>>(x)
|
||||
checkSubtype<KExtensionFunction1<A, Int, Unit>>(y)
|
||||
checkSubtype<KExtensionFunction0<A, String>>(z)
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
checkSubtype<KFunction2<A, Int, Unit>>(y)
|
||||
checkSubtype<KFunction1<A, String>>(z)
|
||||
|
||||
checkSubtype<KExtensionFunction<A, Unit>>(x)
|
||||
checkSubtype<KExtensionFunction<A, Unit>>(y)
|
||||
checkSubtype<KExtensionFunction<A, String>>(z)
|
||||
checkSubtype<KFunction<Unit>>(x)
|
||||
checkSubtype<KFunction<Unit>>(y)
|
||||
checkSubtype<KFunction<String>>(z)
|
||||
}
|
||||
|
||||
+2
-2
@@ -8,5 +8,5 @@ class A {
|
||||
|
||||
fun A?.foo() {}
|
||||
|
||||
val f: KMemberFunction0<A, Unit> = A::foo
|
||||
val g: KExtensionFunction0<A, Unit> = A?::foo
|
||||
val f: KFunction1<A, Unit> = A::foo
|
||||
val g: KFunction1<A, Unit> = A?::foo
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package
|
||||
|
||||
internal val f: kotlin.reflect.KMemberFunction0<A, kotlin.Unit>
|
||||
internal val g: kotlin.reflect.KExtensionFunction0<A, kotlin.Unit>
|
||||
internal val f: kotlin.reflect.KFunction1<A, kotlin.Unit>
|
||||
internal val g: kotlin.reflect.KFunction1<A, kotlin.Unit>
|
||||
internal fun A?.foo(): kotlin.Unit
|
||||
|
||||
internal final class A {
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
import kotlin.reflect.KMemberFunction0
|
||||
import kotlin.reflect.KFunction1
|
||||
|
||||
class A<T>(val t: T) {
|
||||
fun foo(): T = t
|
||||
@@ -9,5 +9,5 @@ class A<T>(val t: T) {
|
||||
fun bar() {
|
||||
val x = A<String>::foo
|
||||
|
||||
checkSubtype<KMemberFunction0<A<String>, String>>(x)
|
||||
checkSubtype<KFunction1<A<String>, String>>(x)
|
||||
}
|
||||
|
||||
Vendored
+6
-6
@@ -1,6 +1,6 @@
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
import kotlin.reflect.KMemberFunction0
|
||||
import kotlin.reflect.KFunction1
|
||||
|
||||
class A {
|
||||
inner class Inner
|
||||
@@ -9,8 +9,8 @@ class A {
|
||||
val x = ::Inner
|
||||
val y = A::Inner
|
||||
|
||||
checkSubtype<KMemberFunction0<A, A.Inner>>(x)
|
||||
checkSubtype<KMemberFunction0<A, Inner>>(y)
|
||||
checkSubtype<KFunction1<A, A.Inner>>(x)
|
||||
checkSubtype<KFunction1<A, Inner>>(y)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -18,7 +18,7 @@ class A {
|
||||
::<!INACCESSIBLE_OUTER_CLASS_EXPRESSION!>Inner<!>
|
||||
val y = A::Inner
|
||||
|
||||
checkSubtype<KMemberFunction0<A, A.Inner>>(y)
|
||||
checkSubtype<KFunction1<A, A.Inner>>(y)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,6 @@ class B {
|
||||
::<!UNRESOLVED_REFERENCE!>Inner<!>
|
||||
val y = A::Inner
|
||||
|
||||
checkSubtype<KMemberFunction0<A, A.Inner>>(y)
|
||||
checkSubtype<KFunction1<A, A.Inner>>(y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+5
-5
@@ -1,6 +1,6 @@
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
import kotlin.reflect.KMemberFunction0
|
||||
import kotlin.reflect.KFunction1
|
||||
|
||||
class A {
|
||||
inner class Inner
|
||||
@@ -10,13 +10,13 @@ fun A.main() {
|
||||
val x = ::Inner
|
||||
val y = A::Inner
|
||||
|
||||
checkSubtype<KMemberFunction0<A, A.Inner>>(x)
|
||||
checkSubtype<KMemberFunction0<A, A.Inner>>(y)
|
||||
checkSubtype<KFunction1<A, A.Inner>>(x)
|
||||
checkSubtype<KFunction1<A, A.Inner>>(y)
|
||||
}
|
||||
|
||||
fun Int.main() {
|
||||
::<!UNRESOLVED_REFERENCE!>Inner<!>
|
||||
val y = A::Inner
|
||||
|
||||
checkSubtype<KMemberFunction0<A, A.Inner>>(y)
|
||||
}
|
||||
checkSubtype<KFunction1<A, A.Inner>>(y)
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -1,6 +1,6 @@
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
import kotlin.reflect.KMemberFunction0
|
||||
import kotlin.reflect.KFunction1
|
||||
|
||||
class A {
|
||||
inner class Inner
|
||||
@@ -10,5 +10,5 @@ fun main() {
|
||||
::<!UNRESOLVED_REFERENCE!>Inner<!>
|
||||
val y = A::Inner
|
||||
|
||||
checkSubtype<KMemberFunction0<A, A.Inner>>(y)
|
||||
}
|
||||
checkSubtype<KFunction1<A, A.Inner>>(y)
|
||||
}
|
||||
|
||||
+2
-2
@@ -9,10 +9,10 @@ class D {
|
||||
|
||||
// FILE: b.kt
|
||||
|
||||
import kotlin.reflect.KMemberFunction0
|
||||
import kotlin.reflect.KFunction1
|
||||
|
||||
fun main() {
|
||||
val x = a.b.c.D::foo
|
||||
|
||||
checkSubtype<KMemberFunction0<a.b.c.D, Int>>(x)
|
||||
checkSubtype<KFunction1<a.b.c.D, Int>>(x)
|
||||
}
|
||||
|
||||
+2
-2
@@ -9,10 +9,10 @@ class D<E, F> {
|
||||
|
||||
// FILE: b.kt
|
||||
|
||||
import kotlin.reflect.KMemberFunction2
|
||||
import kotlin.reflect.KFunction3
|
||||
|
||||
fun main() {
|
||||
val x = a.b.c.D<String, Int>::foo
|
||||
|
||||
checkSubtype<KMemberFunction2<a.b.c.D<String, Int>, String, Int, a.b.c.D<String, Int>>>(x)
|
||||
checkSubtype<KFunction3<a.b.c.D<String, Int>, String, Int, a.b.c.D<String, Int>>>(x)
|
||||
}
|
||||
|
||||
+3
-3
@@ -12,8 +12,8 @@ class A {
|
||||
val y = ::bar
|
||||
val z = ::baz
|
||||
|
||||
checkSubtype<KMemberFunction0<A, Unit>>(x)
|
||||
checkSubtype<KMemberFunction1<A, Int, Unit>>(y)
|
||||
checkSubtype<KMemberFunction0<A, String>>(z)
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
checkSubtype<KFunction2<A, Int, Unit>>(y)
|
||||
checkSubtype<KFunction1<A, String>>(z)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -13,7 +13,7 @@ fun A.main() {
|
||||
val y = ::bar
|
||||
val z = ::baz
|
||||
|
||||
checkSubtype<KMemberFunction0<A, Unit>>(x)
|
||||
checkSubtype<KMemberFunction1<A, Int, Unit>>(y)
|
||||
checkSubtype<KMemberFunction0<A, String>>(z)
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
checkSubtype<KFunction2<A, Int, Unit>>(y)
|
||||
checkSubtype<KFunction1<A, String>>(z)
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -14,8 +14,8 @@ class B {
|
||||
val y = ::bar
|
||||
val z = ::baz
|
||||
|
||||
checkSubtype<KMemberFunction0<A, Unit>>(x)
|
||||
checkSubtype<KMemberFunction1<A, Int, Unit>>(y)
|
||||
checkSubtype<KMemberFunction0<A, String>>(z)
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
checkSubtype<KFunction2<A, Int, Unit>>(y)
|
||||
checkSubtype<KFunction1<A, String>>(z)
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -13,11 +13,11 @@ fun main() {
|
||||
val y = A::bar
|
||||
val z = A::baz
|
||||
|
||||
checkSubtype<KMemberFunction0<A, Unit>>(x)
|
||||
checkSubtype<KMemberFunction1<A, Int, Unit>>(y)
|
||||
checkSubtype<KMemberFunction0<A, String>>(z)
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
checkSubtype<KFunction2<A, Int, Unit>>(y)
|
||||
checkSubtype<KFunction1<A, String>>(z)
|
||||
|
||||
checkSubtype<KMemberFunction<A, Unit>>(x)
|
||||
checkSubtype<KMemberFunction<A, Unit>>(y)
|
||||
checkSubtype<KMemberFunction<A, String>>(z)
|
||||
checkSubtype<KFunction<Unit>>(x)
|
||||
checkSubtype<KFunction<Unit>>(y)
|
||||
checkSubtype<KFunction<String>>(z)
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -1,6 +1,6 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
import kotlin.reflect.KMemberFunction0
|
||||
import kotlin.reflect.KFunction1
|
||||
|
||||
class A {
|
||||
fun foo() = 42
|
||||
@@ -11,5 +11,5 @@ fun A.foo() {}
|
||||
fun main() {
|
||||
val x = A::foo
|
||||
|
||||
checkSubtype<KMemberFunction0<A, Int>>(x)
|
||||
checkSubtype<KFunction1<A, Int>>(x)
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -1,6 +1,6 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
import kotlin.reflect.KMemberFunction0
|
||||
import kotlin.reflect.KFunction1
|
||||
|
||||
fun foo() {}
|
||||
|
||||
@@ -10,6 +10,6 @@ class A {
|
||||
fun main() {
|
||||
val x = ::foo
|
||||
|
||||
checkSubtype<KMemberFunction0<A, Unit>>(x)
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -25,6 +25,6 @@ fun main() {
|
||||
val z = AA::bazbaz
|
||||
|
||||
checkSubtype<KFunction0<Unit>>(x)
|
||||
checkSubtype<KMemberFunction0<AA, Int>>(y)
|
||||
checkSubtype<KExtensionFunction1<AA, String, Unit>>(z)
|
||||
checkSubtype<KFunction1<AA, Int>>(y)
|
||||
checkSubtype<KFunction2<AA, String, Unit>>(z)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user