JVM IR: change generation scheme of property $delegate methods

Generate $delegate method as instance method in
PropertyReferenceDelegationLowering, and remove dispatch receiver later
in MakePropertyDelegateMethodsStatic. The method needs to be static to
be non-overridable (see delegateMethodIsNonOverridable.kt), and public
to be accessible in reflection.

Otherwise we generated incorrect IR where a static function accessed an
instance field of the containing class, which failed in multiple places
including LocalDeclarationsLowering.

 #KT-48350 Fixed
This commit is contained in:
Alexander Udalov
2021-08-21 02:38:11 +02:00
committed by Alexander Udalov
parent 50508da156
commit 04c5bbdcf8
25 changed files with 565 additions and 48 deletions
@@ -9762,6 +9762,16 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/delegatedProperty/protectedVarWithPrivateSet.kt");
}
@TestMetadata("referenceEnclosingClassFieldInReceiver.kt")
public void testReferenceEnclosingClassFieldInReceiver() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/referenceEnclosingClassFieldInReceiver.kt");
}
@TestMetadata("referenceEnclosingClassFieldInReceiver2.kt")
public void testReferenceEnclosingClassFieldInReceiver2() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/referenceEnclosingClassFieldInReceiver2.kt");
}
@TestMetadata("setAsExtensionFun.kt")
public void testSetAsExtensionFun() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/setAsExtensionFun.kt");
@@ -25681,6 +25691,19 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
public void testAllFilesPresentInGetDelegate() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/properties/getDelegate"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@TestMetadata("compiler/testData/codegen/box/reflection/properties/getDelegate/method")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Method extends AbstractIrJsCodegenBoxES6Test {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR_ES6, testDataFilePath);
}
public void testAllFilesPresentInMethod() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/properties/getDelegate/method"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
}
}
@TestMetadata("compiler/testData/codegen/box/reflection/properties/jvmField")
@@ -9168,6 +9168,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/delegatedProperty/protectedVarWithPrivateSet.kt");
}
@TestMetadata("referenceEnclosingClassFieldInReceiver.kt")
public void testReferenceEnclosingClassFieldInReceiver() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/referenceEnclosingClassFieldInReceiver.kt");
}
@TestMetadata("referenceEnclosingClassFieldInReceiver2.kt")
public void testReferenceEnclosingClassFieldInReceiver2() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/referenceEnclosingClassFieldInReceiver2.kt");
}
@TestMetadata("setAsExtensionFun.kt")
public void testSetAsExtensionFun() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/setAsExtensionFun.kt");
@@ -25087,6 +25097,19 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
public void testAllFilesPresentInGetDelegate() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/properties/getDelegate"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@TestMetadata("compiler/testData/codegen/box/reflection/properties/getDelegate/method")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Method extends AbstractIrJsCodegenBoxTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
}
public void testAllFilesPresentInMethod() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/properties/getDelegate/method"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
}
}
@TestMetadata("compiler/testData/codegen/box/reflection/properties/jvmField")
@@ -9168,6 +9168,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/delegatedProperty/protectedVarWithPrivateSet.kt");
}
@TestMetadata("referenceEnclosingClassFieldInReceiver.kt")
public void testReferenceEnclosingClassFieldInReceiver() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/referenceEnclosingClassFieldInReceiver.kt");
}
@TestMetadata("referenceEnclosingClassFieldInReceiver2.kt")
public void testReferenceEnclosingClassFieldInReceiver2() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/referenceEnclosingClassFieldInReceiver2.kt");
}
@TestMetadata("setAsExtensionFun.kt")
public void testSetAsExtensionFun() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/setAsExtensionFun.kt");
@@ -25047,6 +25057,19 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
public void testAllFilesPresentInGetDelegate() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/properties/getDelegate"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
}
@TestMetadata("compiler/testData/codegen/box/reflection/properties/getDelegate/method")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Method extends AbstractJsCodegenBoxTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath);
}
public void testAllFilesPresentInMethod() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/properties/getDelegate/method"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
}
}
}
@TestMetadata("compiler/testData/codegen/box/reflection/properties/jvmField")