diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyReferenceCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyReferenceCodegen.kt index dc23d3bb1e5..588ca8af6ef 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyReferenceCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyReferenceCodegen.kt @@ -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 } diff --git a/compiler/testData/codegen/box/reflection/properties/genericProperty.kt b/compiler/testData/codegen/box/reflection/properties/genericProperty.kt new file mode 100644 index 00000000000..1fc7231c635 --- /dev/null +++ b/compiler/testData/codegen/box/reflection/properties/genericProperty.kt @@ -0,0 +1,11 @@ +// WITH_REFLECT + +import kotlin.test.assertEquals + +data class Box(val element: T) + +fun box(): String { + val p = Box::element + assertEquals("val Box.element: T", p.toString()) + return p.call(Box("OK")) +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 67bd9ba19d5..fbf9108c8b4 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -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"); diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KDeclarationContainerImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KDeclarationContainerImpl.kt index e2fecee2c9a..36dafe2f949 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KDeclarationContainerImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KDeclarationContainerImpl.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" ) }