Unit obtained through a generic substitution should not be mapped to VOID
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
public class GenericUnit {
|
||||
public static class Key<T> {}
|
||||
|
||||
public static <T> T getNull(Key<T> key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> T get(Key<T> key, T t) {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import GenericUnit.*
|
||||
|
||||
val key = Key<Unit>()
|
||||
|
||||
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"
|
||||
}
|
||||
+17
-1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user