Implement script instance capturing in script lowering

for regular classes only. Reimplementing the main behavior of the
old BE and implementing few cases on top of it.
#KT-19423 fixed
This commit is contained in:
Ilya Chernikov
2021-11-24 15:51:02 +01:00
committed by TeamCityServer
parent 87952d63a3
commit cb5e451e05
22 changed files with 659 additions and 94 deletions
@@ -9,6 +9,7 @@ import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TargetBackend;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
@@ -22,7 +23,7 @@ import java.util.regex.Pattern;
@RunWith(JUnit3RunnerWithInners.class)
public class ScriptCodegenTestGenerated extends AbstractScriptCodegenTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
@TestMetadata("adder.kts")
@@ -31,7 +32,7 @@ public class ScriptCodegenTestGenerated extends AbstractScriptCodegenTest {
}
public void testAllFilesPresentInScript() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/script"), Pattern.compile("^(.+)\\.kts$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/script"), Pattern.compile("^(.+)\\.kts$"), null, TargetBackend.JVM, true);
}
@TestMetadata("classLiteralInsideFunction.kts")
@@ -183,4 +184,92 @@ public class ScriptCodegenTestGenerated extends AbstractScriptCodegenTest {
public void testTopLevelTypealias() throws Exception {
runTest("compiler/testData/codegen/script/topLevelTypealias.kts");
}
@TestMetadata("compiler/testData/codegen/script/scriptInstanceCapturing")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ScriptInstanceCapturing extends AbstractScriptCodegenTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
public void testAllFilesPresentInScriptInstanceCapturing() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/script/scriptInstanceCapturing"), Pattern.compile("^(.+)\\.kts$"), null, TargetBackend.JVM, true);
}
@TestMetadata("anonymousObjectCapturesProperty.kts")
public void testAnonymousObjectCapturesProperty() throws Exception {
runTest("compiler/testData/codegen/script/scriptInstanceCapturing/anonymousObjectCapturesProperty.kts");
}
@TestMetadata("classCapturesExtensionIndirect.kts")
public void testClassCapturesExtensionIndirect() throws Exception {
runTest("compiler/testData/codegen/script/scriptInstanceCapturing/classCapturesExtensionIndirect.kts");
}
@TestMetadata("classCapturesExtensionIndirect2x.kts")
public void testClassCapturesExtensionIndirect2x() throws Exception {
runTest("compiler/testData/codegen/script/scriptInstanceCapturing/classCapturesExtensionIndirect2x.kts");
}
@TestMetadata("classCapturesFunction.kts")
public void testClassCapturesFunction() throws Exception {
runTest("compiler/testData/codegen/script/scriptInstanceCapturing/classCapturesFunction.kts");
}
@TestMetadata("classCapturesProperty.kts")
public void testClassCapturesProperty() throws Exception {
runTest("compiler/testData/codegen/script/scriptInstanceCapturing/classCapturesProperty.kts");
}
@TestMetadata("classCapturesPropertyInStringTemplate.kts")
public void testClassCapturesPropertyInStringTemplate() throws Exception {
runTest("compiler/testData/codegen/script/scriptInstanceCapturing/classCapturesPropertyInStringTemplate.kts");
}
@TestMetadata("classCapturesPropertyIndirect.kts")
public void testClassCapturesPropertyIndirect() throws Exception {
runTest("compiler/testData/codegen/script/scriptInstanceCapturing/classCapturesPropertyIndirect.kts");
}
@TestMetadata("classCapturesPropertyIndirect2x.kts")
public void testClassCapturesPropertyIndirect2x() throws Exception {
runTest("compiler/testData/codegen/script/scriptInstanceCapturing/classCapturesPropertyIndirect2x.kts");
}
@TestMetadata("companionCapturesProperty.kts")
public void testCompanionCapturesProperty() throws Exception {
runTest("compiler/testData/codegen/script/scriptInstanceCapturing/companionCapturesProperty.kts");
}
@TestMetadata("enumCapturesProperty.kts")
public void testEnumCapturesProperty() throws Exception {
runTest("compiler/testData/codegen/script/scriptInstanceCapturing/enumCapturesProperty.kts");
}
@TestMetadata("enumEntryCapturesProperty.kts")
public void testEnumEntryCapturesProperty() throws Exception {
runTest("compiler/testData/codegen/script/scriptInstanceCapturing/enumEntryCapturesProperty.kts");
}
@TestMetadata("interfaceCapturesProperty.kts")
public void testInterfaceCapturesProperty() throws Exception {
runTest("compiler/testData/codegen/script/scriptInstanceCapturing/interfaceCapturesProperty.kts");
}
@TestMetadata("objectCapturesProperty.kts")
public void testObjectCapturesProperty() throws Exception {
runTest("compiler/testData/codegen/script/scriptInstanceCapturing/objectCapturesProperty.kts");
}
@TestMetadata("objectCapturesPropertyIndirect.kts")
public void testObjectCapturesPropertyIndirect() throws Exception {
runTest("compiler/testData/codegen/script/scriptInstanceCapturing/objectCapturesPropertyIndirect.kts");
}
@TestMetadata("objectCapturesPropertyViaExtension.kts")
public void testObjectCapturesPropertyViaExtension() throws Exception {
runTest("compiler/testData/codegen/script/scriptInstanceCapturing/objectCapturesPropertyViaExtension.kts");
}
}
}