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:
Alexander Udalov
2015-10-14 16:39:43 +03:00
parent 63dfe13c43
commit ced1edcf98
26 changed files with 122 additions and 218 deletions
@@ -15,6 +15,8 @@ class A(val s1: String, val s2: String) {
}
/*
// TODO: uncomment when callable references to object members are supported
class AWithCompanion {
companion object {
@JvmField public val publicField = "1";
@@ -26,10 +28,11 @@ class AWithCompanion {
}
}
}
*/
fun box(): String {
A("1", "2").testAccessors()
AWithCompanion.testAccessors()
// AWithCompanion.testAccessors()
return "OK"
}
@@ -2,6 +2,7 @@
import java.lang.reflect.Field
import kotlin.reflect.jvm.javaField
import kotlin.reflect.KProperty
import kotlin.test.assertNotEquals
import java.lang.reflect.Modifier
@@ -32,10 +33,12 @@ class AWithCompanion {
@JvmField internal val internalField = "OK";
@JvmField protected val protectedfield = "OK";
operator fun get(name: String) = AWithCompanion.Companion::class.members.single { it.name == name } as KProperty<*>
fun testVisibilities() {
checkVisibility(AWithCompanion.Companion::publicField.javaField!!, Modifier.PUBLIC)
checkVisibility(AWithCompanion.Companion::internalField.javaField!!, Modifier.PUBLIC)
checkVisibility(AWithCompanion.Companion::protectedfield.javaField!!, Modifier.PROTECTED)
checkVisibility(this["publicField"].javaField!!, Modifier.PUBLIC)
checkVisibility(this["internalField"].javaField!!, Modifier.PUBLIC)
checkVisibility(this["protectedfield"].javaField!!, Modifier.PROTECTED)
}
}
}
@@ -45,10 +48,12 @@ object Object {
@JvmField internal val internalField = "OK";
@JvmField protected val protectedfield = "OK";
operator fun get(name: String) = Object::class.members.single { it.name == name } as KProperty<*>
fun testVisibilities() {
checkVisibility(Object::publicField.javaField!!, Modifier.PUBLIC)
checkVisibility(Object::internalField.javaField!!, Modifier.PUBLIC)
checkVisibility(Object::protectedfield.javaField!!, Modifier.PROTECTED)
checkVisibility(this["publicField"].javaField!!, Modifier.PUBLIC)
checkVisibility(this["internalField"].javaField!!, Modifier.PUBLIC)
checkVisibility(this["protectedfield"].javaField!!, Modifier.PROTECTED)
}
}
@@ -61,4 +66,4 @@ fun box(): String {
public fun checkVisibility(field: Field, visibility: Int) {
assertNotEquals(field.modifiers and visibility, 0, "Field ${field} has wrong visibility")
}
}