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 a94eb975a6d..c5c11d03ab3 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java @@ -159,7 +159,9 @@ public class JetTypeMapper { private Type mapReturnType(@NotNull CallableDescriptor descriptor, @Nullable BothSignatureWriter sw) { JetType returnType = descriptor.getReturnType(); assert returnType != null : "Function has no return type: " + descriptor; - if (returnType.equals(KotlinBuiltIns.getInstance().getUnitType()) && !(descriptor instanceof PropertyGetterDescriptor)) { + if (returnType.equals(KotlinBuiltIns.getInstance().getUnitType()) + && !TypeUtils.isNullableType(returnType) + && !(descriptor instanceof PropertyGetterDescriptor)) { if (sw != null) { sw.writeAsmType(Type.VOID_TYPE); } diff --git a/compiler/testData/codegen/boxAgainstJava/platformTypes/GenericUnit.java b/compiler/testData/codegen/boxAgainstJava/platformTypes/GenericUnit.java new file mode 100644 index 00000000000..76e01c52779 --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/platformTypes/GenericUnit.java @@ -0,0 +1,11 @@ +public class GenericUnit { + public static class Key {} + + public static T getNull(Key key) { + return null; + } + + public static T get(Key key, T t) { + return t; + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxAgainstJava/platformTypes/GenericUnit.kt b/compiler/testData/codegen/boxAgainstJava/platformTypes/GenericUnit.kt new file mode 100644 index 00000000000..ca3e3a6dfd6 --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/platformTypes/GenericUnit.kt @@ -0,0 +1,17 @@ +import GenericUnit.* + +val key = Key() + +fun box(): String { + val n1 = getNull(key) + if (n1 != null) return "Fail 1: $n1" + + val n2 = get(key, null) + if (n2 != null) return "Fail 2: $n2" + + val n3 = get(key, Unit) + if (n3 == null) return "Fail 3.0: $n3" + if (n3 != Unit) return "Fail 3.1: $n3" + + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxAgainstJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxAgainstJavaCodegenTestGenerated.java index 3c0647432fb..704a8c0bbfe 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxAgainstJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxAgainstJavaCodegenTestGenerated.java @@ -32,7 +32,7 @@ import java.util.regex.Pattern; @SuppressWarnings("all") @TestMetadata("compiler/testData/codegen/boxAgainstJava") @TestDataPath("$PROJECT_ROOT") -@InnerTestClasses({BlackBoxAgainstJavaCodegenTestGenerated.Annotations.class, BlackBoxAgainstJavaCodegenTestGenerated.CallableReference.class, BlackBoxAgainstJavaCodegenTestGenerated.Constructor.class, BlackBoxAgainstJavaCodegenTestGenerated.Delegation.class, BlackBoxAgainstJavaCodegenTestGenerated.Enum.class, BlackBoxAgainstJavaCodegenTestGenerated.Functions.class, BlackBoxAgainstJavaCodegenTestGenerated.InnerClass.class, BlackBoxAgainstJavaCodegenTestGenerated.NotNullAssertions.class, BlackBoxAgainstJavaCodegenTestGenerated.Property.class, BlackBoxAgainstJavaCodegenTestGenerated.Reflection.class, BlackBoxAgainstJavaCodegenTestGenerated.Sam.class, BlackBoxAgainstJavaCodegenTestGenerated.StaticFun.class, BlackBoxAgainstJavaCodegenTestGenerated.Visibility.class}) +@InnerTestClasses({BlackBoxAgainstJavaCodegenTestGenerated.Annotations.class, BlackBoxAgainstJavaCodegenTestGenerated.CallableReference.class, BlackBoxAgainstJavaCodegenTestGenerated.Constructor.class, BlackBoxAgainstJavaCodegenTestGenerated.Delegation.class, BlackBoxAgainstJavaCodegenTestGenerated.Enum.class, BlackBoxAgainstJavaCodegenTestGenerated.Functions.class, BlackBoxAgainstJavaCodegenTestGenerated.InnerClass.class, BlackBoxAgainstJavaCodegenTestGenerated.NotNullAssertions.class, BlackBoxAgainstJavaCodegenTestGenerated.PlatformTypes.class, BlackBoxAgainstJavaCodegenTestGenerated.Property.class, BlackBoxAgainstJavaCodegenTestGenerated.Reflection.class, BlackBoxAgainstJavaCodegenTestGenerated.Sam.class, BlackBoxAgainstJavaCodegenTestGenerated.StaticFun.class, BlackBoxAgainstJavaCodegenTestGenerated.Visibility.class}) @RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class) public class BlackBoxAgainstJavaCodegenTestGenerated extends AbstractBlackBoxCodegenTest { public void testAllFilesPresentInBoxAgainstJava() throws Exception { @@ -281,6 +281,22 @@ public class BlackBoxAgainstJavaCodegenTestGenerated extends AbstractBlackBoxCod } + @TestMetadata("compiler/testData/codegen/boxAgainstJava/platformTypes") + @TestDataPath("$PROJECT_ROOT") + @RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class) + public static class PlatformTypes extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInPlatformTypes() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxAgainstJava/platformTypes"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("GenericUnit.kt") + public void testGenericUnit() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/platformTypes/GenericUnit.kt"); + doTestAgainstJava(fileName); + } + + } + @TestMetadata("compiler/testData/codegen/boxAgainstJava/property") @TestDataPath("$PROJECT_ROOT") @RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)