From 4545c72f698c204a9b8926957b0878e8a310b9a7 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Wed, 25 Jan 2012 22:23:46 +0400 Subject: [PATCH] properly serialize/parse Nothing type --- .../jet/codegen/BothSignatureWriter.java | 16 ++++++++++++++++ .../org/jetbrains/jet/codegen/JetTypeMapper.java | 10 ++++++++-- .../readKotlinBinaryClass/type/Nothing.kt | 3 +++ .../readKotlinBinaryClass/type/NothingQ.kt | 3 +++ compiler/testData/writeSignature/Nothing.kt | 6 ++++++ compiler/testData/writeSignature/NothingQ.kt | 6 ++++++ 6 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/readKotlinBinaryClass/type/Nothing.kt create mode 100644 compiler/testData/readKotlinBinaryClass/type/NothingQ.kt create mode 100644 compiler/testData/writeSignature/Nothing.kt create mode 100644 compiler/testData/writeSignature/NothingQ.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/BothSignatureWriter.java b/compiler/backend/src/org/jetbrains/jet/codegen/BothSignatureWriter.java index 4d001636d91..6ac4cee31a2 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/BothSignatureWriter.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/BothSignatureWriter.java @@ -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(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java index 2651b387bdd..0b51a0b7a35 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java @@ -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; } diff --git a/compiler/testData/readKotlinBinaryClass/type/Nothing.kt b/compiler/testData/readKotlinBinaryClass/type/Nothing.kt new file mode 100644 index 00000000000..dd6889d5289 --- /dev/null +++ b/compiler/testData/readKotlinBinaryClass/type/Nothing.kt @@ -0,0 +1,3 @@ +package test + +fun nothing(): Nothing = throw Exception() diff --git a/compiler/testData/readKotlinBinaryClass/type/NothingQ.kt b/compiler/testData/readKotlinBinaryClass/type/NothingQ.kt new file mode 100644 index 00000000000..5c7db344aa9 --- /dev/null +++ b/compiler/testData/readKotlinBinaryClass/type/NothingQ.kt @@ -0,0 +1,3 @@ +package test + +fun nothingq(): Nothing? = null diff --git a/compiler/testData/writeSignature/Nothing.kt b/compiler/testData/writeSignature/Nothing.kt new file mode 100644 index 00000000000..f2f54873efa --- /dev/null +++ b/compiler/testData/writeSignature/Nothing.kt @@ -0,0 +1,6 @@ +fun nothing(): Nothing = throw Exception() + +// method: namespace::nothing +// jvm signature: ()V +// generic signature: null +// kotlin signature: ()Ljet/Nothing; diff --git a/compiler/testData/writeSignature/NothingQ.kt b/compiler/testData/writeSignature/NothingQ.kt new file mode 100644 index 00000000000..7a9422dc082 --- /dev/null +++ b/compiler/testData/writeSignature/NothingQ.kt @@ -0,0 +1,6 @@ +fun nothingq(): Nothing? = null + +// method: namespace::nothingq +// jvm signature: ()Ljava/lang/Object; +// generic signature: null +// kotlin signature: ()?Ljet/Nothing;