Scripts: coerce result to the actual expression type

#KT-5622 Fixed
This commit is contained in:
Alexander Udalov
2014-08-13 16:14:28 +04:00
parent 6e46bea821
commit 9c00e1c94d
4 changed files with 35 additions and 2 deletions
@@ -193,7 +193,7 @@ public class ScriptCodegen extends MemberCodegen<JetScript> {
StackValue stackValue =
new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, methodContext, state, this).gen(scriptDeclaration.getBlockExpression());
if (stackValue.type != Type.VOID_TYPE) {
stackValue.put(stackValue.type, iv);
stackValue.put(blockType, iv);
iv.putfield(classType.getInternalName(), ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME, blockType.getDescriptor());
}
@@ -0,0 +1,8 @@
>>> array(1, 2)[0] // KT-5622
1
>>> array(1, 2)[1]
2
>>> array(1, 2).get(0)
1
>>> intArray(1)[0]
1
@@ -0,0 +1,6 @@
>>> Integer.valueOf(42)
42
>>> Integer(239).intValue()
239
>>> java.lang.Long.MIN_VALUE as Any
-9223372036854775808
@@ -31,7 +31,7 @@ import org.jetbrains.jet.repl.AbstractReplInterpreterTest;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/testData/repl")
@InnerTestClasses({ReplInterpreterTestGenerated.Classes.class, ReplInterpreterTestGenerated.Multiline.class, ReplInterpreterTestGenerated.Objects.class, ReplInterpreterTestGenerated.Reflection.class})
@InnerTestClasses({ReplInterpreterTestGenerated.Classes.class, ReplInterpreterTestGenerated.Multiline.class, ReplInterpreterTestGenerated.Objects.class, ReplInterpreterTestGenerated.PrimitiveTypes.class, ReplInterpreterTestGenerated.Reflection.class})
public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest {
public void testAllFilesPresentInRepl() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/repl"), Pattern.compile("^(.+)\\.repl$"), true);
@@ -196,6 +196,24 @@ public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest {
}
@TestMetadata("compiler/testData/repl/primitiveTypes")
public static class PrimitiveTypes extends AbstractReplInterpreterTest {
public void testAllFilesPresentInPrimitiveTypes() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/repl/primitiveTypes"), Pattern.compile("^(.+)\\.repl$"), true);
}
@TestMetadata("arrayOfBoxed.repl")
public void testArrayOfBoxed() throws Exception {
doTest("compiler/testData/repl/primitiveTypes/arrayOfBoxed.repl");
}
@TestMetadata("boxingOnPurpose.repl")
public void testBoxingOnPurpose() throws Exception {
doTest("compiler/testData/repl/primitiveTypes/boxingOnPurpose.repl");
}
}
@TestMetadata("compiler/testData/repl/reflection")
public static class Reflection extends AbstractReplInterpreterTest {
public void testAllFilesPresentInReflection() throws Exception {
@@ -215,6 +233,7 @@ public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest {
suite.addTestSuite(Classes.class);
suite.addTestSuite(Multiline.class);
suite.addTestSuite(Objects.class);
suite.addTestSuite(PrimitiveTypes.class);
suite.addTestSuite(Reflection.class);
return suite;
}