properly serialize/parse Nothing type

This commit is contained in:
Stepan Koltsov
2012-01-25 22:23:46 +04:00
parent bbbddf1c83
commit 4545c72f69
6 changed files with 42 additions and 2 deletions
@@ -167,6 +167,22 @@ public class BothSignatureWriter {
jetSignatureWriter.visitBaseType(c, nullable);
writeAsmType0(Type.getType(String.valueOf(c)));
}
public void writeNothing(boolean nullable) {
if (nullable) {
signatureVisitor().visitClassType("java/lang/Object");
signatureVisitor().visitEnd();
} else {
signatureVisitor().visitBaseType('V');
}
jetSignatureWriter.visitClassType("jet/Nothing", nullable, false);
jetSignatureWriter.visitEnd();
if (nullable) {
writeAsmType0(JetTypeMapper.TYPE_OBJECT);
} else {
writeAsmType0(Type.VOID_TYPE);
}
}
private String makeArrayPrefix() {
StringBuilder sb = new StringBuilder();
@@ -121,15 +121,21 @@ public class JetTypeMapper {
}
@NotNull private Type mapReturnType(final JetType jetType, @Nullable BothSignatureWriter signatureVisitor) {
if (jetType.equals(JetStandardClasses.getUnitType()) || jetType.equals(JetStandardClasses.getNothingType())) {
if (jetType.equals(JetStandardClasses.getUnitType())) {
if (signatureVisitor != null) {
signatureVisitor.writeAsmType(Type.VOID_TYPE, false);
}
return Type.VOID_TYPE;
}
else if (jetType.equals(JetStandardClasses.getNothingType())) {
if (signatureVisitor != null) {
signatureVisitor.writeNothing(false);
}
return Type.VOID_TYPE;
}
if (jetType.equals(JetStandardClasses.getNullableNothingType())) {
if (signatureVisitor != null) {
visitAsmType(signatureVisitor, TYPE_OBJECT, false);
signatureVisitor.writeNothing(true);
}
return TYPE_OBJECT;
}
@@ -0,0 +1,3 @@
package test
fun nothing(): Nothing = throw Exception()
@@ -0,0 +1,3 @@
package test
fun nothingq(): Nothing? = null
@@ -0,0 +1,6 @@
fun nothing(): Nothing = throw Exception()
// method: namespace::nothing
// jvm signature: ()V
// generic signature: null
// kotlin signature: ()Ljet/Nothing;
@@ -0,0 +1,6 @@
fun nothingq(): Nothing? = null
// method: namespace::nothingq
// jvm signature: ()Ljava/lang/Object;
// generic signature: null
// kotlin signature: ()?Ljet/Nothing;