diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 19f0dc3f072..093ac725a21 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -3513,7 +3513,7 @@ The "returned" value of try expression with no finally is either the last expres value.put(boxType(value.type), v); if (opToken != JetTokens.AS_SAFE) { - if (!rightType.isNullable()) { + if (!CodegenUtil.isNullableType(rightType)) { v.dup(); Label nonnull = new Label(); v.ifnonnull(nonnull); diff --git a/compiler/testData/codegen/boxWithStdlib/casts/asWithGeneric.kt b/compiler/testData/codegen/boxWithStdlib/casts/asWithGeneric.kt new file mode 100644 index 00000000000..aed0bdf83d2 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/casts/asWithGeneric.kt @@ -0,0 +1,21 @@ +fun test1() = null as T +fun test2(): T { + val a : Any? = null + return a as T +} + +fun test3() = null as T + +fun box(): String { + if (test1() != null) return "fail: test1" + if (test2() != null) return "fail: test2" + var result3 = "fail" + try { + test3() + } + catch(e: TypeCastException) { + result3 = "OK" + } + if (result3 != "OK") return "fail: test3" + return "OK" +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java index 2d014884dc9..6543439e5eb 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java @@ -31,12 +31,25 @@ import org.jetbrains.jet.codegen.generated.AbstractBlackBoxCodegenTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") @TestMetadata("compiler/testData/codegen/boxWithStdlib") -@InnerTestClasses({BlackBoxWithStdlibCodegenTestGenerated.DataClasses.class, BlackBoxWithStdlibCodegenTestGenerated.FullJdk.class, BlackBoxWithStdlibCodegenTestGenerated.JdkAnnotations.class, BlackBoxWithStdlibCodegenTestGenerated.Ranges.class, BlackBoxWithStdlibCodegenTestGenerated.Regressions.class, BlackBoxWithStdlibCodegenTestGenerated.Strings.class}) +@InnerTestClasses({BlackBoxWithStdlibCodegenTestGenerated.Casts.class, BlackBoxWithStdlibCodegenTestGenerated.DataClasses.class, BlackBoxWithStdlibCodegenTestGenerated.FullJdk.class, BlackBoxWithStdlibCodegenTestGenerated.JdkAnnotations.class, BlackBoxWithStdlibCodegenTestGenerated.Ranges.class, BlackBoxWithStdlibCodegenTestGenerated.Regressions.class, BlackBoxWithStdlibCodegenTestGenerated.Strings.class}) public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCodegenTest { public void testAllFilesPresentInBoxWithStdlib() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/boxWithStdlib"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("compiler/testData/codegen/boxWithStdlib/casts") + public static class Casts extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInCasts() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/boxWithStdlib/casts"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("asWithGeneric.kt") + public void testAsWithGeneric() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/casts/asWithGeneric.kt"); + } + + } + @TestMetadata("compiler/testData/codegen/boxWithStdlib/dataClasses") @InnerTestClasses({DataClasses.Copy.class, DataClasses.Equals.class, DataClasses.Hashcode.class, DataClasses.Tostring.class}) public static class DataClasses extends AbstractBlackBoxCodegenTest { @@ -749,6 +762,7 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode public static Test suite() { TestSuite suite = new TestSuite("BlackBoxWithStdlibCodegenTestGenerated"); suite.addTestSuite(BlackBoxWithStdlibCodegenTestGenerated.class); + suite.addTestSuite(Casts.class); suite.addTest(DataClasses.innerSuite()); suite.addTestSuite(FullJdk.class); suite.addTestSuite(JdkAnnotations.class);