Fix reflection on reference to generic property

See a93484b457 for the similar fix to function
references

 #KT-12967 Fixed
This commit is contained in:
Alexander Udalov
2016-07-04 16:11:45 +03:00
parent 48fe9fb2c0
commit 3b349e9be0
4 changed files with 23 additions and 4 deletions
@@ -228,7 +228,7 @@ class PropertyReferenceCodegen(
initialize(property.type)
}
val method = state.typeMapper.mapAsmMethod(getter)
val method = state.typeMapper.mapAsmMethod(getter.original)
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);
}
@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")
public void testGetExtensionPropertiesMutableVsReadonly() throws Exception {
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
}
if (properties.isEmpty()) {
throw KotlinReflectionInternalError("Property '$name' (JVM signature: $signature) not resolved in $this")
}
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'.
// 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()
}
val debugText = "'$name' (JVM signature: $signature)"
throw KotlinReflectionInternalError(
if (properties.isEmpty()) "Property $debugText not resolved in $this"
else "${properties.size} properties $debugText resolved in $this: $properties"
"${properties.size} properties '$name' (JVM signature: $signature) resolved in $this: $properties"
)
}