Map Nothing to java.lang.Void
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
fun box(): String {
|
||||
// jet.Nothing should not be loaded here
|
||||
val x = "" is Nothing
|
||||
return "OK"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
fun nothing(): Nothing = throw Exception()
|
||||
|
||||
// method: _DefaultPackage::nothing
|
||||
// jvm signature: ()V
|
||||
// generic signature: null
|
||||
@@ -1,5 +0,0 @@
|
||||
fun nothingq(): Nothing? = null
|
||||
|
||||
// method: _DefaultPackage::nothingq
|
||||
// jvm signature: ()Ljava/lang/Object;
|
||||
// generic signature: null
|
||||
@@ -0,0 +1,6 @@
|
||||
class C<T>
|
||||
fun f(p: Nothing, p1: C<Nothing>): Nothing = throw Exception()
|
||||
|
||||
// method: _DefaultPackage::f
|
||||
// jvm signature: (Ljava/lang/Void;LC;)Ljava/lang/Void;
|
||||
// generic signature: (Ljava/lang/Void;LC<Ljava/lang/Void;>;)Ljava/lang/Void;
|
||||
@@ -0,0 +1,6 @@
|
||||
class C<T>
|
||||
fun f(p: Nothing?, p1: C<Nothing?>): Nothing? = throw Exception()
|
||||
|
||||
// method: _DefaultPackage::f
|
||||
// jvm signature: (Ljava/lang/Void;LC;)Ljava/lang/Void;
|
||||
// generic signature: (Ljava/lang/Void;LC<Ljava/lang/Void;>;)Ljava/lang/Void;
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user