KT-8575 Add tests and disable reflection for Java synthetic property references
This commit is contained in:
committed by
teamcity
parent
5116bbc440
commit
f8fd23e373
-41
@@ -1,41 +0,0 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public class J implements K {
|
||||
private String foo;
|
||||
|
||||
@Override
|
||||
public String getFoo() {
|
||||
return foo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFoo(String s) {
|
||||
foo = s;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.reflect.KParameter
|
||||
|
||||
interface K {
|
||||
var foo: String
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val p = J::foo
|
||||
assertEquals("foo", p.name)
|
||||
|
||||
if (p.parameters.size != 1) return "Should have only 1 parameter"
|
||||
if (p.parameters.single().kind != KParameter.Kind.INSTANCE) return "Should have an instance parameter"
|
||||
|
||||
if (J::class.members.none { it == p }) return "No foo in members"
|
||||
|
||||
val j = J()
|
||||
p.setter.call(j, "OK")
|
||||
return p.getter.call(j)
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// !LANGUAGE: +ReferencesToSyntheticJavaProperties
|
||||
// WITH_REFLECT
|
||||
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
private String stringProperty;
|
||||
|
||||
public String getStringProperty() {
|
||||
return stringProperty;
|
||||
}
|
||||
|
||||
public void setStringProperty(String value) {
|
||||
stringProperty = value;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
val stringProperty = J::stringProperty
|
||||
assertEquals("property stringProperty (Kotlin reflection is not available)", stringProperty.toString())
|
||||
try {
|
||||
stringProperty.visibility
|
||||
return "Fail"
|
||||
} catch (e: UnsupportedOperationException) {
|
||||
assertEquals("Kotlin reflection is not yet supported for synthetic Java properties", e.message)
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user