From e8b384eb63770991d1872878d440d0b468092f39 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Mon, 10 Nov 2014 16:44:05 +0300 Subject: [PATCH] Extract IntersectionScope in TypeUtils --- .../jet/lang/resolve/scopes/ChainedScope.kt | 8 ++++--- .../jetbrains/jet/lang/types/TypeUtils.java | 22 +++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/core/descriptors/src/org/jetbrains/jet/lang/resolve/scopes/ChainedScope.kt b/core/descriptors/src/org/jetbrains/jet/lang/resolve/scopes/ChainedScope.kt index 262131fd76f..8a56e103b25 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/resolve/scopes/ChainedScope.kt +++ b/core/descriptors/src/org/jetbrains/jet/lang/resolve/scopes/ChainedScope.kt @@ -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? = null diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/TypeUtils.java b/core/descriptors/src/org/jetbrains/jet/lang/types/TypeUtils.java index 6abcc84cc97..16b5908d312 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/TypeUtils.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/TypeUtils.java @@ -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.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; }