Fix initialization order in REPL
#KT-6843 Fixed
This commit is contained in:
@@ -123,7 +123,7 @@ public class ScriptCodegen extends MemberCodegen<JetScript> {
|
|||||||
@NotNull ScriptDescriptor scriptDescriptor,
|
@NotNull ScriptDescriptor scriptDescriptor,
|
||||||
@NotNull ClassDescriptor classDescriptorForScript,
|
@NotNull ClassDescriptor classDescriptorForScript,
|
||||||
@NotNull ClassBuilder classBuilder,
|
@NotNull ClassBuilder classBuilder,
|
||||||
@NotNull final MethodContext methodContext
|
@NotNull MethodContext methodContext
|
||||||
) {
|
) {
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
Type blockType = typeMapper.mapType(scriptDescriptor.getScriptCodeDescriptor().getReturnType());
|
Type blockType = typeMapper.mapType(scriptDescriptor.getScriptCodeDescriptor().getReturnType());
|
||||||
@@ -143,7 +143,7 @@ public class ScriptCodegen extends MemberCodegen<JetScript> {
|
|||||||
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
|
|
||||||
final InstructionAdapter iv = new InstructionAdapter(mv);
|
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||||
|
|
||||||
Type classType = typeMapper.mapType(classDescriptorForScript);
|
Type classType = typeMapper.mapType(classDescriptorForScript);
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ public class ScriptCodegen extends MemberCodegen<JetScript> {
|
|||||||
|
|
||||||
iv.load(0, classType);
|
iv.load(0, classType);
|
||||||
|
|
||||||
final FrameMap frameMap = new FrameMap();
|
FrameMap frameMap = new FrameMap();
|
||||||
frameMap.enterTemp(OBJECT_TYPE);
|
frameMap.enterTemp(OBJECT_TYPE);
|
||||||
|
|
||||||
for (ScriptDescriptor importedScript : context.getEarlierScripts()) {
|
for (ScriptDescriptor importedScript : context.getEarlierScripts()) {
|
||||||
@@ -167,13 +167,6 @@ public class ScriptCodegen extends MemberCodegen<JetScript> {
|
|||||||
frameMap.enter(parameter, argTypes[i + add]);
|
frameMap.enter(parameter, argTypes[i + add]);
|
||||||
}
|
}
|
||||||
|
|
||||||
generateInitializers(new Function0<ExpressionCodegen>() {
|
|
||||||
@Override
|
|
||||||
public ExpressionCodegen invoke() {
|
|
||||||
return new ExpressionCodegen(iv, frameMap, Type.VOID_TYPE, methodContext, state, ScriptCodegen.this);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
int offset = 1;
|
int offset = 1;
|
||||||
|
|
||||||
for (ScriptDescriptor earlierScript : context.getEarlierScripts()) {
|
for (ScriptDescriptor earlierScript : context.getEarlierScripts()) {
|
||||||
@@ -192,9 +185,16 @@ public class ScriptCodegen extends MemberCodegen<JetScript> {
|
|||||||
iv.putfield(classType.getInternalName(), parameter.getName().getIdentifier(), parameterType.getDescriptor());
|
iv.putfield(classType.getInternalName(), parameter.getName().getIdentifier(), parameterType.getDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
StackValue stackValue =
|
final ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, methodContext, state, this);
|
||||||
new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, methodContext, state, this)
|
|
||||||
.gen(scriptDeclaration.getBlockExpression());
|
generateInitializers(new Function0<ExpressionCodegen>() {
|
||||||
|
@Override
|
||||||
|
public ExpressionCodegen invoke() {
|
||||||
|
return codegen;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
StackValue stackValue = codegen.gen(scriptDeclaration.getBlockExpression());
|
||||||
if (stackValue.type != Type.VOID_TYPE) {
|
if (stackValue.type != Type.VOID_TYPE) {
|
||||||
StackValue.Field resultValue = StackValue
|
StackValue.Field resultValue = StackValue
|
||||||
.field(blockType, classType, ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME, false, StackValue.LOCAL_0);
|
.field(blockType, classType, ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME, false, StackValue.LOCAL_0);
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
>>> [data] class Person(val name: String)
|
||||||
|
>>> var x: String? = "hello"
|
||||||
|
>>> val y = x?.let { Person(it) }
|
||||||
|
>>> y
|
||||||
|
Person(name=hello)
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
>>> val x = ""
|
||||||
|
>>> val y = x
|
||||||
|
>>> x == y
|
||||||
|
true
|
||||||
@@ -30,7 +30,7 @@ import java.util.regex.Pattern;
|
|||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
@TestMetadata("compiler/testData/repl")
|
@TestMetadata("compiler/testData/repl")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@InnerTestClasses({ReplInterpreterTestGenerated.Classes.class, ReplInterpreterTestGenerated.Multiline.class, ReplInterpreterTestGenerated.Objects.class, ReplInterpreterTestGenerated.PrimitiveTypes.class, ReplInterpreterTestGenerated.Reflection.class})
|
@InnerTestClasses({ReplInterpreterTestGenerated.Classes.class, ReplInterpreterTestGenerated.Multiline.class, ReplInterpreterTestGenerated.Objects.class, ReplInterpreterTestGenerated.PrimitiveTypes.class, ReplInterpreterTestGenerated.Reflection.class, ReplInterpreterTestGenerated.Regressions.class})
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest {
|
public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest {
|
||||||
public void testAllFilesPresentInRepl() throws Exception {
|
public void testAllFilesPresentInRepl() throws Exception {
|
||||||
@@ -97,6 +97,12 @@ public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("simpleTwoVals.repl")
|
||||||
|
public void testSimpleTwoVals() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/repl/simpleTwoVals.repl");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("syntaxErrors.repl")
|
@TestMetadata("syntaxErrors.repl")
|
||||||
public void testSyntaxErrors() throws Exception {
|
public void testSyntaxErrors() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/repl/syntaxErrors.repl");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/repl/syntaxErrors.repl");
|
||||||
@@ -267,4 +273,19 @@ public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/repl/regressions")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Regressions extends AbstractReplInterpreterTest {
|
||||||
|
public void testAllFilesPresentInRegressions() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/repl/regressions"), Pattern.compile("^(.+)\\.repl$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt6843.repl")
|
||||||
|
public void testKt6843() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/repl/regressions/kt6843.repl");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user