From 60d8ada2163563ee9c70b0ad177318892d3bf67c Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Wed, 31 Aug 2011 19:16:07 +0200 Subject: [PATCH] added test for KT-248 --- idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java | 4 ++-- idea/testData/codegen/regressions/kt248.jet | 7 +++++++ .../org/jetbrains/jet/codegen/PrimitiveTypesTest.java | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 idea/testData/codegen/regressions/kt248.jet diff --git a/idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 26b45bb9f5f..b7b1a4a3d9b 100644 --- a/idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -1613,7 +1613,7 @@ public class ExpressionCodegen extends JetVisitor { if (!(descriptor instanceof ClassDescriptor)) { throw new UnsupportedOperationException("don't know how to handle non-class types in as/as?"); } - Type type = typeMapper.mapType(jetType, OwnerKind.INTERFACE); + Type type = typeMapper.boxType(typeMapper.mapType(jetType, OwnerKind.INTERFACE)); generateInstanceOf(StackValue.expression(OBJECT_TYPE, expression.getLeft(), this), jetType, true); Label isInstance = new Label(); v.ifne(isInstance); @@ -1739,7 +1739,7 @@ public class ExpressionCodegen extends JetVisitor { if (leaveExpressionOnStack) { v.dup(); } - Type type = typeMapper.mapType(jetType, OwnerKind.INTERFACE); + Type type = typeMapper.boxType(typeMapper.mapType(jetType, OwnerKind.INTERFACE)); v.instanceOf(type); } } diff --git a/idea/testData/codegen/regressions/kt248.jet b/idea/testData/codegen/regressions/kt248.jet new file mode 100644 index 00000000000..0607b21341f --- /dev/null +++ b/idea/testData/codegen/regressions/kt248.jet @@ -0,0 +1,7 @@ +fun box() : String { + val b = true as? Boolean //exception + val i = 1 as Int //exception + val j = 1 as Int? //ok + val s = "s" as String //ok + return "OK" +} diff --git a/idea/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java b/idea/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java index 41a81f3713e..389d6be3b04 100644 --- a/idea/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java +++ b/idea/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java @@ -270,4 +270,8 @@ public class PrimitiveTypesTest extends CodegenTestCase { public void testKt243 () throws Exception { blackBoxFile("regressions/kt243.jet"); } + + public void testKt248 () throws Exception { + blackBoxFile("regressions/kt248.jet"); + } }