Fix exception from reflection on local delegated properties

The problem was that in JvmSerializerExtension.writeLocalProperties, we
only serialized metadata for local properties, but indices generated in
MemberCodegen.generatePropertyMetadataArrayFieldIfNeeded were among all
delegated properties in the class (not only local). This behaved
incorrectly as long as there was a local and a non-local delegated
property in the same class. For example, if there were 5 non-local
properties and then one local, that local property would get the index 5
and the synthetic signature "<v#5>". But there would only be one
Property entry in the metadata, and so reflection would fail here trying
to load the 5th element of the list which contains only one element.

Now, the index for a local delegated property is computed only as the
number of _local_ delegated properties above it in the class, i.e. the
first local delegated property gets index 0 (and synthetic signature
"<v#0>"), the next one -- index 1, and so on.

 #KT-23413 Fixed
This commit is contained in:
Alexander Udalov
2018-06-13 18:00:12 +02:00
parent b8722ad213
commit 5d76e463d3
8 changed files with 71 additions and 10 deletions
@@ -18410,6 +18410,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/reflection/properties/localDelegated/inlineFun.kt");
}
@TestMetadata("localAndNonLocal.kt")
public void testLocalAndNonLocal() throws Exception {
runTest("compiler/testData/codegen/box/reflection/properties/localDelegated/localAndNonLocal.kt");
}
@TestMetadata("localDelegatedProperty.kt")
public void testLocalDelegatedProperty() throws Exception {
runTest("compiler/testData/codegen/box/reflection/properties/localDelegated/localDelegatedProperty.kt");