Nullable and Nothing supported
This commit is contained in:
@@ -8,12 +8,12 @@ import java.util.*;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class JetStandardClasses {
|
||||
private static final TypeConstructor NOTHING = new TypeConstructor(
|
||||
|
||||
private static ClassDescriptor NOTHING_CLASS = new ClassDescriptor(
|
||||
Collections.<Attribute>emptyList(),
|
||||
"Nothing",
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
new AbstractCollection<Type>() {
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return o instanceof Type;
|
||||
@@ -28,7 +28,8 @@ public class JetStandardClasses {
|
||||
public int size() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
private static final ClassDescriptor ANY = new ClassDescriptor(
|
||||
Collections.<Attribute>emptyList(),
|
||||
@@ -85,8 +86,13 @@ public class JetStandardClasses {
|
||||
private static final Type BOOLEAN_TYPE = new TypeImpl(getBoolean().getTypeConstructor(), STUB);
|
||||
private static final Type STRING_TYPE = new TypeImpl(getString().getTypeConstructor(), STUB);
|
||||
private static final Type UNIT_TYPE = new TypeImpl(getTuple(0).getTypeConstructor(), STUB);
|
||||
private static final Type NOTHING_TYPE = new TypeImpl(NOTHING, STUB);
|
||||
private static final Type NULLABLE_NOTHING_TYPE = new TypeImpl(Collections.<Attribute>emptyList(), NOTHING, true, Collections.<TypeProjection>emptyList(), TypeMemberDomain.EMPTY);
|
||||
private static final Type NOTHING_TYPE = new TypeImpl(getNothing().getTypeConstructor(), STUB);
|
||||
private static final Type NULLABLE_NOTHING_TYPE = new TypeImpl(
|
||||
Collections.<Attribute>emptyList(),
|
||||
getNothing().getTypeConstructor(),
|
||||
true,
|
||||
Collections.<TypeProjection>emptyList(),
|
||||
TypeMemberDomain.EMPTY);
|
||||
|
||||
@NotNull
|
||||
public static ClassDescriptor getAny() {
|
||||
@@ -143,6 +149,11 @@ public class JetStandardClasses {
|
||||
return STRING;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ClassDescriptor getNothing() {
|
||||
return NOTHING_CLASS;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ClassDescriptor getTuple(int size) {
|
||||
return TUPLE[size];
|
||||
|
||||
@@ -75,6 +75,9 @@ public class JetTypeChecker {
|
||||
if (!supertype.isNullable() && subtype.isNullable()) {
|
||||
return false;
|
||||
}
|
||||
if (subtype.getConstructor() == JetStandardClasses.getNothing().getTypeConstructor()) {
|
||||
return true;
|
||||
}
|
||||
@Nullable Type closestSupertype = findCorrespondingSupertype(subtype, supertype);
|
||||
if (closestSupertype == null) {
|
||||
return false;
|
||||
|
||||
@@ -177,6 +177,25 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
assertSubtype("Derived_T<Any>", "Base_T<in Int>");
|
||||
}
|
||||
|
||||
public void testNullable() throws Exception {
|
||||
assertSubtype("Any?", "Any?");
|
||||
assertSubtype("Any", "Any?");
|
||||
assertNotSubtype("Any?", "Any");
|
||||
assertSubtype("Int", "Any?");
|
||||
assertSubtype("Int?", "Any?");
|
||||
assertNotSubtype("Int?", "Any");
|
||||
}
|
||||
|
||||
public void testNothing() throws Exception {
|
||||
assertSubtype("Nothing", "Any");
|
||||
assertSubtype("Nothing?", "Any?");
|
||||
assertNotSubtype("Nothing?", "Any");
|
||||
|
||||
assertSubtype("Nothing", "Int");
|
||||
assertSubtype("Nothing?", "Int?");
|
||||
assertNotSubtype("Nothing?", "Int");
|
||||
}
|
||||
|
||||
public void testImplicitConversions() throws Exception {
|
||||
assertConvertibleTo("1", JetStandardClasses.getByteType());
|
||||
}
|
||||
@@ -254,6 +273,8 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
return JetStandardClasses.getTuple(0);
|
||||
} else if ("Any".equals(name)) {
|
||||
return JetStandardClasses.getAny();
|
||||
} else if ("Nothing".equals(name)) {
|
||||
return JetStandardClasses.getNothing();
|
||||
}
|
||||
if (CLASSES.isEmpty()) {
|
||||
for (String classDeclaration : CLASS_DECLARATIONS) {
|
||||
|
||||
Reference in New Issue
Block a user