K2 Scripting: implement basic metadata serialization support
#KT-62305 fixed NB: kotlin reflection do not see script class constructor after this change, and it's ok, since the fact that the script is compiled into a class is an implementation detail. If needed, java reflection could be used to access the constructor.
This commit is contained in:
committed by
Space Team
parent
122f16fc18
commit
31f9e9e7a8
+1
-1
@@ -35,7 +35,7 @@ import kotlin.script.experimental.jvmhost.JvmScriptCompiler
|
||||
*/
|
||||
class ImplicitsFromScriptResultTest : TestCase() {
|
||||
|
||||
fun testImplicits() = expectTestToFailOnK2 {
|
||||
fun testImplicits() {
|
||||
// the implementation of the Compiler Host doesn't work with IR - the inter-script symbol table
|
||||
// should be maintained to make it run (see latest REPL compiler implementations for details
|
||||
// TODO: consider either fix it or rewrite to the REPL compiler
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ fun main(args: Array<String>) {
|
||||
model("")
|
||||
}
|
||||
testClass<AbstractK2KotlinpTest> {
|
||||
model("")
|
||||
model("", pattern = "^(.*)\\.kts?$")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+8
-3
@@ -26,7 +26,7 @@ public class K2KotlinpTestGenerated extends AbstractK2KotlinpTest {
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInTestData() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("libraries/tools/kotlinp/testData"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("libraries/tools/kotlinp/testData"), Pattern.compile("^(.*)\\.kts?$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("Annotations.kt")
|
||||
@@ -109,6 +109,11 @@ public class K2KotlinpTestGenerated extends AbstractK2KotlinpTest {
|
||||
runTest("libraries/tools/kotlinp/testData/Properties.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("scriptSimple.kts")
|
||||
public void testScriptSimple() throws Exception {
|
||||
runTest("libraries/tools/kotlinp/testData/scriptSimple.kts");
|
||||
}
|
||||
|
||||
@TestMetadata("SimpleClass.kt")
|
||||
public void testSimpleClass() throws Exception {
|
||||
runTest("libraries/tools/kotlinp/testData/SimpleClass.kt");
|
||||
@@ -163,7 +168,7 @@ public class K2KotlinpTestGenerated extends AbstractK2KotlinpTest {
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInJvmDefault() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("libraries/tools/kotlinp/testData/jvmDefault"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("libraries/tools/kotlinp/testData/jvmDefault"), Pattern.compile("^(.*)\\.kts?$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("withCompatibility.kt")
|
||||
@@ -186,7 +191,7 @@ public class K2KotlinpTestGenerated extends AbstractK2KotlinpTest {
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInLocalClasses() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("libraries/tools/kotlinp/testData/localClasses"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("libraries/tools/kotlinp/testData/localClasses"), Pattern.compile("^(.*)\\.kts?$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("AnonymousObject.kt")
|
||||
|
||||
@@ -95,7 +95,7 @@ private fun compileAndPrintAllFiles(
|
||||
}
|
||||
|
||||
if (compareWithTxt) {
|
||||
KotlinTestUtils.assertEqualsToFile(File(file.path.replace(".kt", ".txt")), main.toString())
|
||||
KotlinTestUtils.assertEqualsToFile(File(file.path.replace(".kt.?".toRegex(), ".txt")), main.toString())
|
||||
}
|
||||
|
||||
if (readWriteAndCompare && InTextDirectivesUtils.findStringWithPrefixes(file.readText(), "// NO_READ_WRITE_COMPARE") == null) {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
val a = 42
|
||||
|
||||
class A(val p: String)
|
||||
|
||||
fun A.foo() = p
|
||||
|
||||
class B<T>(val v: T & Any)
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// ScriptSimple.class
|
||||
// ------------------------------------------
|
||||
public final class ScriptSimple {
|
||||
|
||||
// signature: foo(LScriptSimple$A;)Ljava/lang/String;
|
||||
public final fun A.foo(): kotlin/String
|
||||
|
||||
// field: a:I
|
||||
// getter: getA()I
|
||||
public final val a: kotlin/Int /* = ... */
|
||||
public final get
|
||||
|
||||
// nested class: A
|
||||
|
||||
// nested class: B
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// ScriptSimple$A.class
|
||||
// ------------------------------------------
|
||||
public final class A : kotlin/Any {
|
||||
|
||||
// signature: <init>(Ljava/lang/String;)V
|
||||
public constructor(p: kotlin/String)
|
||||
|
||||
// field: p:Ljava/lang/String;
|
||||
// getter: getP()Ljava/lang/String;
|
||||
public final val p: kotlin/String
|
||||
public final get
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// ScriptSimple$B.class
|
||||
// ------------------------------------------
|
||||
public final class B<T#0 /* T */> : kotlin/Any {
|
||||
|
||||
// requires language version 1.7.0 (level=ERROR)
|
||||
// signature: <init>(Ljava/lang/Object;)V
|
||||
public constructor(v: T#0 & Any)
|
||||
|
||||
// requires language version 1.7.0 (level=ERROR)
|
||||
// field: v:Ljava/lang/Object;
|
||||
// getter: getV()Ljava/lang/Object;
|
||||
public final val v: T#0 & Any
|
||||
public final get
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// META-INF/test-module.kotlin_module
|
||||
// ------------------------------------------
|
||||
module {
|
||||
}
|
||||
Reference in New Issue
Block a user