From 9c00e1c94d46501171be2cdd65f8b3a0bcc85404 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 13 Aug 2014 16:14:28 +0400 Subject: [PATCH] Scripts: coerce result to the actual expression type #KT-5622 Fixed --- .../jetbrains/jet/codegen/ScriptCodegen.java | 2 +- .../repl/primitiveTypes/arrayOfBoxed.repl | 8 +++++++ .../repl/primitiveTypes/boxingOnPurpose.repl | 6 ++++++ .../repl/ReplInterpreterTestGenerated.java | 21 ++++++++++++++++++- 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/repl/primitiveTypes/arrayOfBoxed.repl create mode 100644 compiler/testData/repl/primitiveTypes/boxingOnPurpose.repl diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java index 5381280e4a1..d82a51dd8ef 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java @@ -193,7 +193,7 @@ public class ScriptCodegen extends MemberCodegen { 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()); } diff --git a/compiler/testData/repl/primitiveTypes/arrayOfBoxed.repl b/compiler/testData/repl/primitiveTypes/arrayOfBoxed.repl new file mode 100644 index 00000000000..6eccb6c639b --- /dev/null +++ b/compiler/testData/repl/primitiveTypes/arrayOfBoxed.repl @@ -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 diff --git a/compiler/testData/repl/primitiveTypes/boxingOnPurpose.repl b/compiler/testData/repl/primitiveTypes/boxingOnPurpose.repl new file mode 100644 index 00000000000..63035485204 --- /dev/null +++ b/compiler/testData/repl/primitiveTypes/boxingOnPurpose.repl @@ -0,0 +1,6 @@ +>>> Integer.valueOf(42) +42 +>>> Integer(239).intValue() +239 +>>> java.lang.Long.MIN_VALUE as Any +-9223372036854775808 diff --git a/compiler/tests/org/jetbrains/jet/repl/ReplInterpreterTestGenerated.java b/compiler/tests/org/jetbrains/jet/repl/ReplInterpreterTestGenerated.java index dbe8f761604..cd35f505fc6 100644 --- a/compiler/tests/org/jetbrains/jet/repl/ReplInterpreterTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/repl/ReplInterpreterTestGenerated.java @@ -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; }