Extract IntersectionScope in TypeUtils

This commit is contained in:
Pavel V. Talanov
2014-11-10 16:44:05 +03:00
parent 2533887253
commit e8b384eb63
2 changed files with 23 additions and 7 deletions
@@ -24,9 +24,11 @@ import java.util.*
import org.jetbrains.jet.lang.resolve.scopes.JetScopeSelectorUtil.*
public class ChainedScope(private val containingDeclaration: DeclarationDescriptor?/* it's nullable as a hack for TypeUtils.intersect() */,
private val debugName: String,
vararg scopes: JetScope) : JetScope {
public open class ChainedScope(
private val containingDeclaration: DeclarationDescriptor?/* it's nullable as a hack for TypeUtils.intersect() */,
private val debugName: String,
vararg scopes: JetScope
) : JetScope {
private val scopeChain = scopes.clone()
private var implicitReceiverHierarchy: List<ReceiverParameterDescriptor>? = null
@@ -98,7 +98,7 @@ public class TypeUtils {
}
public static final JetType NO_EXPECTED_TYPE = new SpecialType("NO_EXPECTED_TYPE");
public static final JetType UNIT_EXPECTED_TYPE = new SpecialType("UNIT_EXPECTED_TYPE");
public static boolean noExpectedType(@NotNull JetType type) {
@@ -171,7 +171,7 @@ public class TypeUtils {
allNullable &= type.isNullable();
nullabilityStripped.add(makeNotNullable(type));
}
if (nothingTypePresent) {
return allNullable ? KotlinBuiltIns.getInstance().getNullableNothingType() : KotlinBuiltIns.getInstance().getNothingType();
}
@@ -227,7 +227,21 @@ public class TypeUtils {
constructor,
allNullable,
Collections.<TypeProjection>emptyList(),
new ChainedScope(null, "member scope for intersection type " + constructor, scopes)); // TODO : check intersectibility, don't use a chanied scope
new IntersectionScope(constructor, scopes)
);
}
// TODO : check intersectibility, don't use a chanied scope
public static class IntersectionScope extends ChainedScope {
public IntersectionScope(@NotNull TypeConstructor constructor, @NotNull JetScope[] scopes) {
super(null, "member scope for intersection type " + constructor, scopes);
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
throw new UnsupportedOperationException("Should not call getContainingDeclaration on intersection scope " + this);
}
}
private static class TypeUnifier {
@@ -450,7 +464,7 @@ public class TypeUtils {
if (supertype.isNullable()) return true;
if (hasNullableSuperType(supertype)) return true;
}
return false;
}