Prohibit callable references to object members
To be able to make them more useful in the future, i.e. bound to the object instance
This commit is contained in:
@@ -501,6 +501,7 @@ public interface Errors {
|
|||||||
DiagnosticFactory1<JetExpression, CallableMemberDescriptor> EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED = DiagnosticFactory1.create(ERROR);
|
DiagnosticFactory1<JetExpression, CallableMemberDescriptor> EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory0<JetExpression> CALLABLE_REFERENCE_LHS_NOT_A_CLASS = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<JetExpression> CALLABLE_REFERENCE_LHS_NOT_A_CLASS = DiagnosticFactory0.create(ERROR);
|
||||||
DiagnosticFactory0<JetExpression> CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<JetExpression> CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS = DiagnosticFactory0.create(ERROR);
|
||||||
|
DiagnosticFactory0<JetExpression> CALLABLE_REFERENCE_TO_OBJECT_MEMBER = DiagnosticFactory0.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory0<JetExpression> CLASS_LITERAL_LHS_NOT_A_CLASS = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<JetExpression> CLASS_LITERAL_LHS_NOT_A_CLASS = DiagnosticFactory0.create(ERROR);
|
||||||
DiagnosticFactory0<JetExpression> ARRAY_CLASS_LITERAL_REQUIRES_ARGUMENT = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<JetExpression> ARRAY_CLASS_LITERAL_REQUIRES_ARGUMENT = DiagnosticFactory0.create(ERROR);
|
||||||
|
|||||||
+1
@@ -675,6 +675,7 @@ public class DefaultErrorMessages {
|
|||||||
MAP.put(CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS,
|
MAP.put(CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS,
|
||||||
"Left-hand side of a callable reference with a receiver parameter cannot be empty. " +
|
"Left-hand side of a callable reference with a receiver parameter cannot be empty. " +
|
||||||
"Please specify the type of the receiver before '::' explicitly");
|
"Please specify the type of the receiver before '::' explicitly");
|
||||||
|
MAP.put(CALLABLE_REFERENCE_TO_OBJECT_MEMBER, "Callable references to object members are not supported");
|
||||||
|
|
||||||
MAP.put(CLASS_LITERAL_LHS_NOT_A_CLASS, "Only classes are allowed on the left hand side of a class literal");
|
MAP.put(CLASS_LITERAL_LHS_NOT_A_CLASS, "Only classes are allowed on the left hand side of a class literal");
|
||||||
MAP.put(ARRAY_CLASS_LITERAL_REQUIRES_ARGUMENT, "kotlin.Array class literal requires a type argument, please specify one in angle brackets");
|
MAP.put(ARRAY_CLASS_LITERAL_REQUIRES_ARGUMENT, "kotlin.Array class literal requires a type argument, please specify one in angle brackets");
|
||||||
|
|||||||
+4
@@ -696,6 +696,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
context.trace.report(CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS.on(reference));
|
context.trace.report(CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS.on(reference));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DescriptorUtils.isObject(descriptor.getContainingDeclaration())) {
|
||||||
|
context.trace.report(CALLABLE_REFERENCE_TO_OBJECT_MEMBER.on(reference));
|
||||||
|
}
|
||||||
|
|
||||||
return CallableReferencesPackage.createReflectionTypeForResolvedCallableReference(expression, descriptor, context, components.reflectionTypes);
|
return CallableReferencesPackage.createReflectionTypeForResolvedCallableReference(expression, descriptor, context, components.reflectionTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
-17
@@ -1,17 +0,0 @@
|
|||||||
import A.foo
|
|
||||||
import A.bar
|
|
||||||
|
|
||||||
object A {
|
|
||||||
fun foo() = "O"
|
|
||||||
fun String.foo() = "K"
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun bar(s: Int) = "OK"
|
|
||||||
}
|
|
||||||
|
|
||||||
fun box(): String {
|
|
||||||
val static = (::bar)(0)
|
|
||||||
if (static != "OK") return "1"
|
|
||||||
|
|
||||||
return (::foo)() + (String::foo)("")
|
|
||||||
}
|
|
||||||
Vendored
-13
@@ -1,13 +0,0 @@
|
|||||||
object A {
|
|
||||||
var result = "Fail"
|
|
||||||
|
|
||||||
fun foo() {
|
|
||||||
result = "OK"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun box(): String {
|
|
||||||
val x = A::foo
|
|
||||||
x(A)
|
|
||||||
return A.result
|
|
||||||
}
|
|
||||||
Vendored
-13
@@ -1,13 +0,0 @@
|
|||||||
object A {
|
|
||||||
var result = "Fail"
|
|
||||||
|
|
||||||
fun foo(newResult: String) {
|
|
||||||
result = newResult
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun box(): String {
|
|
||||||
val x = A::foo
|
|
||||||
x(A, "OK")
|
|
||||||
return A.result
|
|
||||||
}
|
|
||||||
-15
@@ -1,15 +0,0 @@
|
|||||||
class A {
|
|
||||||
companion object B {
|
|
||||||
var state: String = "12345"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun box(): String {
|
|
||||||
val p = A.B::state
|
|
||||||
|
|
||||||
if (p.name != "state") return "Fail state: ${p.name}"
|
|
||||||
if (p.get(A.B) != "12345") return "Fail value: ${p.get(A.B)}"
|
|
||||||
p.set(A.B, "OK")
|
|
||||||
|
|
||||||
return p[A.B]
|
|
||||||
}
|
|
||||||
Vendored
-33
@@ -1,33 +0,0 @@
|
|||||||
import A.foo
|
|
||||||
import A.bar
|
|
||||||
import A.baz
|
|
||||||
|
|
||||||
object A {
|
|
||||||
var foo = "NotOk"
|
|
||||||
var String.foo: String
|
|
||||||
get() = "K"
|
|
||||||
set(i) {}
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
val bar: String = "OK"
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
val String.baz: String
|
|
||||||
get() = "OK"
|
|
||||||
}
|
|
||||||
|
|
||||||
fun box(): String {
|
|
||||||
|
|
||||||
val static = (::bar).get()
|
|
||||||
if (static != "OK") return static
|
|
||||||
|
|
||||||
val staticExt = (String::baz).get("a")
|
|
||||||
if (staticExt != "OK") return staticExt
|
|
||||||
|
|
||||||
val nonExt = ::foo
|
|
||||||
|
|
||||||
nonExt.set("O")
|
|
||||||
val ext = String::foo
|
|
||||||
ext.set("", "Whatever")
|
|
||||||
return nonExt.get() + ext.get("")
|
|
||||||
}
|
|
||||||
@@ -4,12 +4,15 @@ fun box(): String {
|
|||||||
assertEquals(java.lang.Integer.MIN_VALUE, Int.MIN_VALUE)
|
assertEquals(java.lang.Integer.MIN_VALUE, Int.MIN_VALUE)
|
||||||
assertEquals(java.lang.Byte.MAX_VALUE, Byte.MAX_VALUE)
|
assertEquals(java.lang.Byte.MAX_VALUE, Byte.MAX_VALUE)
|
||||||
|
|
||||||
|
/*
|
||||||
|
// TODO: uncomment when callable references to object members are supported
|
||||||
assertEquals("MIN_VALUE", (Int.Companion::MIN_VALUE).name)
|
assertEquals("MIN_VALUE", (Int.Companion::MIN_VALUE).name)
|
||||||
assertEquals("MAX_VALUE", (Double.Companion::MAX_VALUE).name)
|
assertEquals("MAX_VALUE", (Double.Companion::MAX_VALUE).name)
|
||||||
assertEquals("MIN_VALUE", (Float.Companion::MIN_VALUE).name)
|
assertEquals("MIN_VALUE", (Float.Companion::MIN_VALUE).name)
|
||||||
assertEquals("MAX_VALUE", (Long.Companion::MAX_VALUE).name)
|
assertEquals("MAX_VALUE", (Long.Companion::MAX_VALUE).name)
|
||||||
assertEquals("MIN_VALUE", (Short.Companion::MIN_VALUE).name)
|
assertEquals("MIN_VALUE", (Short.Companion::MIN_VALUE).name)
|
||||||
assertEquals("MAX_VALUE", (Byte.Companion::MAX_VALUE).name)
|
assertEquals("MAX_VALUE", (Byte.Companion::MAX_VALUE).name)
|
||||||
|
*/
|
||||||
|
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ class A(val s1: String, val s2: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
// TODO: uncomment when callable references to object members are supported
|
||||||
class AWithCompanion {
|
class AWithCompanion {
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField public val publicField = "1";
|
@JvmField public val publicField = "1";
|
||||||
@@ -26,10 +28,11 @@ class AWithCompanion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
A("1", "2").testAccessors()
|
A("1", "2").testAccessors()
|
||||||
AWithCompanion.testAccessors()
|
// AWithCompanion.testAccessors()
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import java.lang.reflect.Field
|
import java.lang.reflect.Field
|
||||||
import kotlin.reflect.jvm.javaField
|
import kotlin.reflect.jvm.javaField
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
import kotlin.test.assertNotEquals
|
import kotlin.test.assertNotEquals
|
||||||
import java.lang.reflect.Modifier
|
import java.lang.reflect.Modifier
|
||||||
|
|
||||||
@@ -32,10 +33,12 @@ class AWithCompanion {
|
|||||||
@JvmField internal val internalField = "OK";
|
@JvmField internal val internalField = "OK";
|
||||||
@JvmField protected val protectedfield = "OK";
|
@JvmField protected val protectedfield = "OK";
|
||||||
|
|
||||||
|
operator fun get(name: String) = AWithCompanion.Companion::class.members.single { it.name == name } as KProperty<*>
|
||||||
|
|
||||||
fun testVisibilities() {
|
fun testVisibilities() {
|
||||||
checkVisibility(AWithCompanion.Companion::publicField.javaField!!, Modifier.PUBLIC)
|
checkVisibility(this["publicField"].javaField!!, Modifier.PUBLIC)
|
||||||
checkVisibility(AWithCompanion.Companion::internalField.javaField!!, Modifier.PUBLIC)
|
checkVisibility(this["internalField"].javaField!!, Modifier.PUBLIC)
|
||||||
checkVisibility(AWithCompanion.Companion::protectedfield.javaField!!, Modifier.PROTECTED)
|
checkVisibility(this["protectedfield"].javaField!!, Modifier.PROTECTED)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,10 +48,12 @@ object Object {
|
|||||||
@JvmField internal val internalField = "OK";
|
@JvmField internal val internalField = "OK";
|
||||||
@JvmField protected val protectedfield = "OK";
|
@JvmField protected val protectedfield = "OK";
|
||||||
|
|
||||||
|
operator fun get(name: String) = Object::class.members.single { it.name == name } as KProperty<*>
|
||||||
|
|
||||||
fun testVisibilities() {
|
fun testVisibilities() {
|
||||||
checkVisibility(Object::publicField.javaField!!, Modifier.PUBLIC)
|
checkVisibility(this["publicField"].javaField!!, Modifier.PUBLIC)
|
||||||
checkVisibility(Object::internalField.javaField!!, Modifier.PUBLIC)
|
checkVisibility(this["internalField"].javaField!!, Modifier.PUBLIC)
|
||||||
checkVisibility(Object::protectedfield.javaField!!, Modifier.PROTECTED)
|
checkVisibility(this["protectedfield"].javaField!!, Modifier.PROTECTED)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
import kotlin.platform.platformStatic
|
|
||||||
|
|
||||||
object A {
|
|
||||||
|
|
||||||
val b: String = "OK"
|
|
||||||
|
|
||||||
@platformStatic var c: String = "Fail"
|
|
||||||
|
|
||||||
@platformStatic fun test1() : String {
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
@platformStatic fun test2() : String {
|
|
||||||
return test1()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun test3(): String {
|
|
||||||
return "1".test5()
|
|
||||||
}
|
|
||||||
|
|
||||||
@platformStatic fun test4(): String {
|
|
||||||
return "1".test5()
|
|
||||||
}
|
|
||||||
|
|
||||||
@platformStatic fun String.test5() : String {
|
|
||||||
return this + b
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun box(): String {
|
|
||||||
if ((A::test1)(A) != "OK") return "fail 1"
|
|
||||||
|
|
||||||
if ((A::test2)(A) != "OK") return "fail 2"
|
|
||||||
|
|
||||||
if ((A::test3)(A) != "1OK") return "fail 3"
|
|
||||||
|
|
||||||
if ((A::test4)(A) != "1OK") return "fail 4"
|
|
||||||
|
|
||||||
(A::c).set(A, "OK")
|
|
||||||
|
|
||||||
if (((A::c).get(A)) != "OK") return "fail 5"
|
|
||||||
|
|
||||||
return "OK"
|
|
||||||
}
|
|
||||||
+7
-3
@@ -1,6 +1,8 @@
|
|||||||
import kotlin.jvm.JvmStatic as static
|
import kotlin.jvm.JvmStatic as static
|
||||||
import kotlin.reflect.jvm.isAccessible
|
import kotlin.reflect.jvm.isAccessible
|
||||||
import kotlin.reflect.KCallable
|
import kotlin.reflect.KCallable
|
||||||
|
import kotlin.reflect.KFunction
|
||||||
|
import kotlin.reflect.KMutableProperty
|
||||||
|
|
||||||
var foo: String = ""
|
var foo: String = ""
|
||||||
|
|
||||||
@@ -11,7 +13,9 @@ class A(private var bar: String = "") {
|
|||||||
object O {
|
object O {
|
||||||
private @static var baz: String = ""
|
private @static var baz: String = ""
|
||||||
|
|
||||||
@static fun getBaz() = O::baz.apply { isAccessible = true }
|
@static fun getBaz() = (O::class.members.single { it.name == "baz" } as KMutableProperty<*>).apply { isAccessible = true }
|
||||||
|
|
||||||
|
fun getGetBaz() = O::class.members.single { it.name == "getBaz" } as KFunction<*>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun check(callable: KCallable<*>, vararg args: Any?) {
|
fun check(callable: KCallable<*>, vararg args: Any?) {
|
||||||
@@ -44,8 +48,8 @@ fun box(): String {
|
|||||||
check(::A)
|
check(::A)
|
||||||
check(::A, null, "")
|
check(::A, null, "")
|
||||||
|
|
||||||
check(O::getBaz)
|
check(O.getGetBaz())
|
||||||
check(O::getBaz, null, "")
|
check(O.getGetBaz(), null, "")
|
||||||
|
|
||||||
|
|
||||||
val f = ::foo
|
val f = ::foo
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class C {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
(Obj::foo).call(Obj)
|
(Obj::class.members.single { it.name == "foo" }).call(Obj)
|
||||||
(C.Companion::bar).call(C.Companion)
|
(C.Companion::class.members.single { it.name == "bar" }).call(C.Companion)
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+9
-7
@@ -4,32 +4,34 @@ object Obj {
|
|||||||
@static fun foo(s: String) {}
|
@static fun foo(s: String) {}
|
||||||
@static fun bar() {}
|
@static fun bar() {}
|
||||||
@static fun sly(obj: Obj) {}
|
@static fun sly(obj: Obj) {}
|
||||||
|
|
||||||
|
operator fun get(name: String) = Obj::class.members.single { it.name == name }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
// This should succeed
|
// This should succeed
|
||||||
(Obj::foo).call(Obj, "")
|
(Obj["foo"]).call(Obj, "")
|
||||||
(Obj::bar).call(Obj)
|
(Obj["bar"]).call(Obj)
|
||||||
(Obj::sly).call(Obj, Obj)
|
(Obj["sly"]).call(Obj, Obj)
|
||||||
|
|
||||||
// This shouldn't: first argument should always be Obj
|
// This shouldn't: first argument should always be Obj
|
||||||
try {
|
try {
|
||||||
(Obj::foo).call(null, "")
|
(Obj["foo"]).call(null, "")
|
||||||
return "Fail foo"
|
return "Fail foo"
|
||||||
} catch (e: IllegalArgumentException) {}
|
} catch (e: IllegalArgumentException) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
(Obj::bar).call("")
|
(Obj["bar"]).call("")
|
||||||
return "Fail bar"
|
return "Fail bar"
|
||||||
} catch (e: IllegalArgumentException) {}
|
} catch (e: IllegalArgumentException) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
(Obj::sly).call(Obj)
|
(Obj["sly"]).call(Obj)
|
||||||
return "Fail sly 1"
|
return "Fail sly 1"
|
||||||
} catch (e: IllegalArgumentException) {}
|
} catch (e: IllegalArgumentException) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
(Obj::sly).call(null, Obj)
|
(Obj["sly"]).call(null, Obj)
|
||||||
return "Fail sly 2"
|
return "Fail sly 2"
|
||||||
} catch (e: IllegalArgumentException) {}
|
} catch (e: IllegalArgumentException) {}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ fun nullableUnit(unit: Boolean): Unit? = if (unit) Unit else null
|
|||||||
fun box(): String {
|
fun box(): String {
|
||||||
assertEquals(Unit, ::foo.call())
|
assertEquals(Unit, ::foo.call())
|
||||||
assertEquals(Unit, A::bar.call(A()))
|
assertEquals(Unit, A::bar.call(A()))
|
||||||
assertEquals(Unit, O::baz.call(O))
|
assertEquals(Unit, O::class.members.single { it.name == "baz" }.call(O))
|
||||||
|
|
||||||
assertEquals(Unit, (::nullableUnit).call(true))
|
assertEquals(Unit, (::nullableUnit).call(true))
|
||||||
assertEquals(null, (::nullableUnit).call(false))
|
assertEquals(null, (::nullableUnit).call(false))
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ object Obj {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
val f = Obj::foo
|
val f = Obj::class.members.single { it.name == "foo" }
|
||||||
|
|
||||||
// Any object method currently requires the object instance passed
|
// Any object method currently requires the object instance passed
|
||||||
try {
|
try {
|
||||||
|
|||||||
compiler/testData/codegen/boxWithStdlib/reflection/mapping/platformStatic/companionObjectFunction.kt
Vendored
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
import kotlin.jvm.JvmStatic as static
|
import kotlin.jvm.JvmStatic as static
|
||||||
|
import kotlin.reflect.KFunction
|
||||||
import kotlin.reflect.jvm.*
|
import kotlin.reflect.jvm.*
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.failsWith
|
import kotlin.test.failsWith
|
||||||
@@ -10,7 +11,7 @@ class C {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
val foo = C.Companion::foo
|
val foo = C.Companion::class.members.single { it.name == "foo" } as KFunction<*>
|
||||||
|
|
||||||
val j = foo.javaMethod ?: return "Fail: no Java method found for C::foo"
|
val j = foo.javaMethod ?: return "Fail: no Java method found for C::foo"
|
||||||
assertEquals(3, j.invoke(C, "abc"))
|
assertEquals(3, j.invoke(C, "abc"))
|
||||||
|
|||||||
Vendored
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
import kotlin.jvm.JvmStatic as static
|
import kotlin.jvm.JvmStatic as static
|
||||||
|
import kotlin.reflect.KFunction
|
||||||
import kotlin.reflect.jvm.*
|
import kotlin.reflect.jvm.*
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
@@ -7,7 +8,7 @@ object O {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
val foo = O::foo
|
val foo = O::class.members.single { it.name == "foo" } as KFunction<*>
|
||||||
|
|
||||||
val j = foo.javaMethod ?: return "Fail: no Java method found for O::foo"
|
val j = foo.javaMethod ?: return "Fail: no Java method found for O::foo"
|
||||||
assertEquals(3, j.invoke(null, "abc"))
|
assertEquals(3, j.invoke(null, "abc"))
|
||||||
|
|||||||
+6
-4
@@ -11,11 +11,13 @@ object O {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
assertEquals(listOf(javaClass<A>(), javaClass<java.lang.Long>()), A::foo.parameters.map { it.type.javaType })
|
val foo = A::foo
|
||||||
assertEquals(listOf(javaClass<O>(), javaClass<A>()), O::bar.parameters.map { it.type.javaType })
|
assertEquals(listOf(javaClass<A>(), javaClass<java.lang.Long>()), foo.parameters.map { it.type.javaType })
|
||||||
|
assertEquals(java.lang.Long.TYPE, foo.returnType.javaType)
|
||||||
|
|
||||||
assertEquals(java.lang.Long.TYPE, A::foo.returnType.javaType)
|
val bar = O::class.members.single { it.name == "bar" }
|
||||||
assertEquals(javaClass<String>(), O::bar.returnType.javaType)
|
assertEquals(listOf(javaClass<O>(), javaClass<A>()), bar.parameters.map { it.type.javaType })
|
||||||
|
assertEquals(javaClass<String>(), bar.returnType.javaType)
|
||||||
|
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||||
|
|
||||||
|
import Obj.ext
|
||||||
|
import A.Companion.ext2
|
||||||
|
|
||||||
|
object Obj {
|
||||||
|
fun foo() {}
|
||||||
|
val bar = 2
|
||||||
|
val String.ext: String get() = this
|
||||||
|
}
|
||||||
|
|
||||||
|
class A {
|
||||||
|
companion object {
|
||||||
|
fun foo() {}
|
||||||
|
val bar = 2
|
||||||
|
val String.ext2: String get() = this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
Obj::<!CALLABLE_REFERENCE_TO_OBJECT_MEMBER!>foo<!>
|
||||||
|
Obj::<!CALLABLE_REFERENCE_TO_OBJECT_MEMBER!>bar<!>
|
||||||
|
String::<!CALLABLE_REFERENCE_TO_OBJECT_MEMBER!>ext<!>
|
||||||
|
|
||||||
|
A.Companion::<!CALLABLE_REFERENCE_TO_OBJECT_MEMBER!>foo<!>
|
||||||
|
A.Companion::<!CALLABLE_REFERENCE_TO_OBJECT_MEMBER!>bar<!>
|
||||||
|
String::<!CALLABLE_REFERENCE_TO_OBJECT_MEMBER!>ext2<!>
|
||||||
|
|
||||||
|
A::<!UNRESOLVED_REFERENCE!>foo<!>
|
||||||
|
A::<!UNRESOLVED_REFERENCE!>bar<!>
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun test(): kotlin.Unit
|
||||||
|
|
||||||
|
public final class A {
|
||||||
|
public constructor A()
|
||||||
|
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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
|
||||||
|
public companion object Companion {
|
||||||
|
private constructor Companion()
|
||||||
|
public final val bar: kotlin.Int = 2
|
||||||
|
public final val kotlin.String.ext2: kotlin.String
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public final fun foo(): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public object Obj {
|
||||||
|
private constructor Obj()
|
||||||
|
public final val bar: kotlin.Int = 2
|
||||||
|
public final val kotlin.String.ext: kotlin.String
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public final fun foo(): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
@@ -1611,6 +1611,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("objectMembersUnsupported.kt")
|
||||||
|
public void testObjectMembersUnsupported() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/callableReference/objectMembersUnsupported.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("unused.kt")
|
@TestMetadata("unused.kt")
|
||||||
public void testUnused() throws Exception {
|
public void testUnused() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/callableReference/unused.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/callableReference/unused.kt");
|
||||||
|
|||||||
-36
@@ -564,12 +564,6 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
|||||||
doTestWithStdlib(fileName);
|
doTestWithStdlib(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("memberImportedFromObject.kt")
|
|
||||||
public void testMemberImportedFromObject() throws Exception {
|
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/function/memberImportedFromObject.kt");
|
|
||||||
doTestWithStdlib(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("nestedConstructorFromClass.kt")
|
@TestMetadata("nestedConstructorFromClass.kt")
|
||||||
public void testNestedConstructorFromClass() throws Exception {
|
public void testNestedConstructorFromClass() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/function/nestedConstructorFromClass.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/function/nestedConstructorFromClass.kt");
|
||||||
@@ -594,18 +588,6 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
|||||||
doTestWithStdlib(fileName);
|
doTestWithStdlib(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("objectMemberUnitNoArgs.kt")
|
|
||||||
public void testObjectMemberUnitNoArgs() throws Exception {
|
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/function/objectMemberUnitNoArgs.kt");
|
|
||||||
doTestWithStdlib(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("objectMemberUnitOneStringArg.kt")
|
|
||||||
public void testObjectMemberUnitOneStringArg() throws Exception {
|
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/function/objectMemberUnitOneStringArg.kt");
|
|
||||||
doTestWithStdlib(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("overloadedFun.kt")
|
@TestMetadata("overloadedFun.kt")
|
||||||
public void testOverloadedFun() throws Exception {
|
public void testOverloadedFun() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/function/overloadedFun.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/function/overloadedFun.kt");
|
||||||
@@ -810,12 +792,6 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
|||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/callableReference/property"), Pattern.compile("^(.+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/callableReference/property"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("classObjectVar.kt")
|
|
||||||
public void testClassObjectVar() throws Exception {
|
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/property/classObjectVar.kt");
|
|
||||||
doTestWithStdlib(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("delegated.kt")
|
@TestMetadata("delegated.kt")
|
||||||
public void testDelegated() throws Exception {
|
public void testDelegated() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/property/delegated.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/property/delegated.kt");
|
||||||
@@ -864,12 +840,6 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
|||||||
doTestWithStdlib(fileName);
|
doTestWithStdlib(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("memberImportedFromObject.kt")
|
|
||||||
public void testMemberImportedFromObject() throws Exception {
|
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/property/memberImportedFromObject.kt");
|
|
||||||
doTestWithStdlib(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("overriddenInSubclass.kt")
|
@TestMetadata("overriddenInSubclass.kt")
|
||||||
public void testOverriddenInSubclass() throws Exception {
|
public void testOverriddenInSubclass() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/property/overriddenInSubclass.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/property/overriddenInSubclass.kt");
|
||||||
@@ -2548,12 +2518,6 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
|||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/platformStatic"), Pattern.compile("^(.+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/platformStatic"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("callableRef.kt")
|
|
||||||
public void testCallableRef() throws Exception {
|
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/platformStatic/callableRef.kt");
|
|
||||||
doTestWithStdlib(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("closure.kt")
|
@TestMetadata("closure.kt")
|
||||||
public void testClosure() throws Exception {
|
public void testClosure() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/platformStatic/closure.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/platformStatic/closure.kt");
|
||||||
|
|||||||
-4
@@ -114,10 +114,6 @@ public final class FunctionCallableReferenceTest extends AbstractCallableReferen
|
|||||||
checkFooBoxIsOk();
|
checkFooBoxIsOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClassMemberOverriddenInObject() throws Exception {
|
|
||||||
checkFooBoxIsOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testClassMemberAndExtension() throws Exception {
|
public void testClassMemberAndExtension() throws Exception {
|
||||||
checkFooBoxIsOk();
|
checkFooBoxIsOk();
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
-15
@@ -1,15 +0,0 @@
|
|||||||
package foo
|
|
||||||
|
|
||||||
open class A {
|
|
||||||
open fun foo(a:String,b:String): String = "fooA:" + a + b
|
|
||||||
}
|
|
||||||
|
|
||||||
object B : A() {
|
|
||||||
override fun foo(a:String,b:String): String = "fooB:" + a + b
|
|
||||||
}
|
|
||||||
|
|
||||||
fun box(): String {
|
|
||||||
var ref = B::foo
|
|
||||||
val result = ref(B, "1", "2")
|
|
||||||
return (if (result == "fooB:12") "OK" else result)
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user