Fix reflection on reference to generic property
See a93484b457 for the similar fix to function
references
#KT-12967 Fixed
This commit is contained in:
@@ -228,7 +228,7 @@ class PropertyReferenceCodegen(
|
|||||||
initialize(property.type)
|
initialize(property.type)
|
||||||
}
|
}
|
||||||
|
|
||||||
val method = state.typeMapper.mapAsmMethod(getter)
|
val method = state.typeMapper.mapAsmMethod(getter.original)
|
||||||
return method.name + method.descriptor
|
return method.name + method.descriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// WITH_REFLECT
|
||||||
|
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
data class Box<T>(val element: T)
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val p = Box<String>::element
|
||||||
|
assertEquals("val Box<T>.element: T", p.toString())
|
||||||
|
return p.call(Box("OK"))
|
||||||
|
}
|
||||||
@@ -12393,6 +12393,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("genericProperty.kt")
|
||||||
|
public void testGenericProperty() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/properties/genericProperty.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("getExtensionPropertiesMutableVsReadonly.kt")
|
@TestMetadata("getExtensionPropertiesMutableVsReadonly.kt")
|
||||||
public void testGetExtensionPropertiesMutableVsReadonly() throws Exception {
|
public void testGetExtensionPropertiesMutableVsReadonly() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/properties/getExtensionPropertiesMutableVsReadonly.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/properties/getExtensionPropertiesMutableVsReadonly.kt");
|
||||||
|
|||||||
@@ -109,6 +109,10 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain
|
|||||||
RuntimeTypeMapper.mapPropertySignature(descriptor).asString() == signature
|
RuntimeTypeMapper.mapPropertySignature(descriptor).asString() == signature
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (properties.isEmpty()) {
|
||||||
|
throw KotlinReflectionInternalError("Property '$name' (JVM signature: $signature) not resolved in $this")
|
||||||
|
}
|
||||||
|
|
||||||
if (properties.size != 1) {
|
if (properties.size != 1) {
|
||||||
// Try working around the case of a Java class with a field 'foo' and a method 'getFoo' which overrides Kotlin property 'foo'.
|
// Try working around the case of a Java class with a field 'foo' and a method 'getFoo' which overrides Kotlin property 'foo'.
|
||||||
// Such class has two property descriptors with the name 'foo' in its scope and they may be indistinguishable from each other.
|
// Such class has two property descriptors with the name 'foo' in its scope and they may be indistinguishable from each other.
|
||||||
@@ -129,10 +133,8 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain
|
|||||||
return mostVisibleProperties.first()
|
return mostVisibleProperties.first()
|
||||||
}
|
}
|
||||||
|
|
||||||
val debugText = "'$name' (JVM signature: $signature)"
|
|
||||||
throw KotlinReflectionInternalError(
|
throw KotlinReflectionInternalError(
|
||||||
if (properties.isEmpty()) "Property $debugText not resolved in $this"
|
"${properties.size} properties '$name' (JVM signature: $signature) resolved in $this: $properties"
|
||||||
else "${properties.size} properties $debugText resolved in $this: $properties"
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user