Don't create KProperty instance for synthetic field
#KT-5759 Fixed
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import kotlin.reflect.jvm.kotlin
|
||||
|
||||
class A {
|
||||
// There's a synthetic "$kotlinClass" field here
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
for (field in javaClass<A>().getDeclaredFields()) {
|
||||
val prop = field.kotlin
|
||||
if (prop != null) return "Fail, property found: $prop"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -2782,6 +2782,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticFields.kt")
|
||||
public void testSyntheticFields() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/mapping/syntheticFields.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelProperty.kt")
|
||||
public void testTopLevelProperty() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/mapping/topLevelProperty.kt");
|
||||
|
||||
@@ -118,12 +118,15 @@ public val Class<*>.kotlinPackage: KPackage
|
||||
get() = KPackageImpl(this)
|
||||
|
||||
|
||||
// TODO: make nullable to filter out synthetic fields (KT-5759)
|
||||
/**
|
||||
* Returns a [KProperty] instance corresponding to the given Java [Field] instance.
|
||||
* Returns a [KProperty] instance corresponding to the given Java [Field] instance,
|
||||
* or `null` if this field cannot be represented by a Kotlin property
|
||||
* (for example, if it is a synthetic field).
|
||||
*/
|
||||
public val Field.kotlin: KProperty<*>
|
||||
public val Field.kotlin: KProperty<*>?
|
||||
get() {
|
||||
if (isSynthetic()) return null
|
||||
|
||||
val clazz = getDeclaringClass()
|
||||
val name = getName()
|
||||
val modifiers = getModifiers()
|
||||
|
||||
Reference in New Issue
Block a user