diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java index 35b54b70a8e..38186e411d6 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java @@ -197,18 +197,6 @@ public class JetTypeMapper extends BindingTraceAware { } return Type.VOID_TYPE; } - else if (jetType.equals(KotlinBuiltIns.getInstance().getNothingType())) { - if (signatureVisitor != null) { - signatureVisitor.writeNothing(); - } - return Type.VOID_TYPE; - } - if (jetType.equals(KotlinBuiltIns.getInstance().getNullableNothingType())) { - if (signatureVisitor != null) { - signatureVisitor.writeNullableNothing(); - } - return AsmTypeConstants.OBJECT_TYPE; - } return mapType(jetType, signatureVisitor, JetTypeMapperMode.VALUE, Variance.OUT_VARIANCE, false); } diff --git a/compiler/testData/codegen/box/typeMapping/nothing.kt b/compiler/testData/codegen/box/typeMapping/nothing.kt new file mode 100644 index 00000000000..6947866d6ee --- /dev/null +++ b/compiler/testData/codegen/box/typeMapping/nothing.kt @@ -0,0 +1,5 @@ +fun box(): String { + // jet.Nothing should not be loaded here + val x = "" is Nothing + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/typeMapping/nullableNothing.kt b/compiler/testData/codegen/box/typeMapping/nullableNothing.kt new file mode 100644 index 00000000000..85622c6e9a2 --- /dev/null +++ b/compiler/testData/codegen/box/typeMapping/nullableNothing.kt @@ -0,0 +1,6 @@ + +fun box(): String { + // This used to be problematic because of an attempt to load jet/Nothing class + val x = "" is Nothing? + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/writeSignature/Nothing.kt b/compiler/testData/writeSignature/Nothing.kt deleted file mode 100644 index df2b18e8942..00000000000 --- a/compiler/testData/writeSignature/Nothing.kt +++ /dev/null @@ -1,5 +0,0 @@ -fun nothing(): Nothing = throw Exception() - -// method: _DefaultPackage::nothing -// jvm signature: ()V -// generic signature: null \ No newline at end of file diff --git a/compiler/testData/writeSignature/NothingQ.kt b/compiler/testData/writeSignature/NothingQ.kt deleted file mode 100644 index ad9097f54e9..00000000000 --- a/compiler/testData/writeSignature/NothingQ.kt +++ /dev/null @@ -1,5 +0,0 @@ -fun nothingq(): Nothing? = null - -// method: _DefaultPackage::nothingq -// jvm signature: ()Ljava/lang/Object; -// generic signature: null \ No newline at end of file diff --git a/compiler/testData/writeSignature/nothing/nothing.kt b/compiler/testData/writeSignature/nothing/nothing.kt new file mode 100644 index 00000000000..0912e0bd844 --- /dev/null +++ b/compiler/testData/writeSignature/nothing/nothing.kt @@ -0,0 +1,6 @@ +class C +fun f(p: Nothing, p1: C): Nothing = throw Exception() + +// method: _DefaultPackage::f +// jvm signature: (Ljava/lang/Void;LC;)Ljava/lang/Void; +// generic signature: (Ljava/lang/Void;LC;)Ljava/lang/Void; diff --git a/compiler/testData/writeSignature/nothing/nullableNothing.kt b/compiler/testData/writeSignature/nothing/nullableNothing.kt new file mode 100644 index 00000000000..3eaecfbf5d3 --- /dev/null +++ b/compiler/testData/writeSignature/nothing/nullableNothing.kt @@ -0,0 +1,6 @@ +class C +fun f(p: Nothing?, p1: C): Nothing? = throw Exception() + +// method: _DefaultPackage::f +// jvm signature: (Ljava/lang/Void;LC;)Ljava/lang/Void; +// generic signature: (Ljava/lang/Void;LC;)Ljava/lang/Void; diff --git a/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java index 00a87687dd6..4bd0e9cf2e3 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java @@ -127,7 +127,7 @@ public class ClassGenTest extends CodegenTestCase { public void testKt309() { loadText("fun box() = null"); Method method = generateFunction("box"); - assertEquals(method.getReturnType().getName(), "java.lang.Object"); + assertEquals(method.getReturnType().getName(), "java.lang.Void"); } /* diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java index 1c2c18cd03b..873b55e1d9c 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -4352,6 +4352,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest("compiler/testData/codegen/box/typeMapping/hashable.kt"); } + @TestMetadata("nothing.kt") + public void testNothing() throws Exception { + doTest("compiler/testData/codegen/box/typeMapping/nothing.kt"); + } + + @TestMetadata("nullableNothing.kt") + public void testNullableNothing() throws Exception { + doTest("compiler/testData/codegen/box/typeMapping/nullableNothing.kt"); + } + } @TestMetadata("compiler/testData/codegen/box/unit") diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/WriteSignatureTestGenerated.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/WriteSignatureTestGenerated.java index 1bbb14867fe..d1efcc08ddb 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/WriteSignatureTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/WriteSignatureTestGenerated.java @@ -31,7 +31,7 @@ import org.jetbrains.jet.jvm.compiler.AbstractWriteSignatureTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") @TestMetadata("compiler/testData/writeSignature") -@InnerTestClasses({WriteSignatureTestGenerated.Constructor.class, WriteSignatureTestGenerated.DeclarationSiteVariance.class}) +@InnerTestClasses({WriteSignatureTestGenerated.Constructor.class, WriteSignatureTestGenerated.DeclarationSiteVariance.class, WriteSignatureTestGenerated.Nothing.class}) public class WriteSignatureTestGenerated extends AbstractWriteSignatureTest { public void testAllFilesPresentInWriteSignature() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/writeSignature"), Pattern.compile("^(.+)\\.kt$"), true); @@ -97,16 +97,6 @@ public class WriteSignatureTestGenerated extends AbstractWriteSignatureTest { doTest("compiler/testData/writeSignature/NonGeneric.kt"); } - @TestMetadata("Nothing.kt") - public void testNothing() throws Exception { - doTest("compiler/testData/writeSignature/Nothing.kt"); - } - - @TestMetadata("NothingQ.kt") - public void testNothingQ() throws Exception { - doTest("compiler/testData/writeSignature/NothingQ.kt"); - } - @TestMetadata("VarargCharSequence.kt") public void testVarargCharSequence() throws Exception { doTest("compiler/testData/writeSignature/VarargCharSequence.kt"); @@ -263,11 +253,30 @@ public class WriteSignatureTestGenerated extends AbstractWriteSignatureTest { } + @TestMetadata("compiler/testData/writeSignature/nothing") + public static class Nothing extends AbstractWriteSignatureTest { + public void testAllFilesPresentInNothing() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/writeSignature/nothing"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("nothing.kt") + public void testNothing() throws Exception { + doTest("compiler/testData/writeSignature/nothing/nothing.kt"); + } + + @TestMetadata("nullableNothing.kt") + public void testNullableNothing() throws Exception { + doTest("compiler/testData/writeSignature/nothing/nullableNothing.kt"); + } + + } + public static Test suite() { TestSuite suite = new TestSuite("WriteSignatureTestGenerated"); suite.addTestSuite(WriteSignatureTestGenerated.class); suite.addTestSuite(Constructor.class); suite.addTestSuite(DeclarationSiteVariance.class); + suite.addTestSuite(Nothing.class); return suite; } } diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/mapping/JavaToKotlinClassMapBuilder.java b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/mapping/JavaToKotlinClassMapBuilder.java index a052cb70842..50a4c549b5c 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/mapping/JavaToKotlinClassMapBuilder.java +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/mapping/JavaToKotlinClassMapBuilder.java @@ -44,6 +44,7 @@ public abstract class JavaToKotlinClassMapBuilder { register(Annotation.class, kotlinBuiltIns.getAnnotation()); register(Deprecated.class, kotlinBuiltIns.getDeprecatedAnnotation(), Direction.JAVA_TO_KOTLIN); register(Object.class, kotlinBuiltIns.getHashable(), Direction.KOTLIN_TO_JAVA); + register(Void.class, kotlinBuiltIns.getNothing(), Direction.KOTLIN_TO_JAVA); register(Iterable.class, kotlinBuiltIns.getIterable(), kotlinBuiltIns.getMutableIterable()); register(Iterator.class, kotlinBuiltIns.getIterator(), kotlinBuiltIns.getMutableIterator());