diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt index 91014269ff2..20c448932b7 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt @@ -294,18 +294,19 @@ class LazyJavaTypeResolver( } private class Impl(lowerBound: KotlinType, upperBound: KotlinType) : - DelegatingFlexibleType(lowerBound, upperBound, FlexibleJavaClassifierTypeFactory), CustomTypeVariable, Specificity { + DelegatingFlexibleType(lowerBound, upperBound, FlexibleJavaClassifierTypeFactory), CustomTypeVariable { + + override val delegateType: KotlinType get() = lowerBound override fun getCapability(capabilityClass: Class): T? { @Suppress("UNCHECKED_CAST") - return when (capabilityClass) { - CustomTypeVariable::class.java, Specificity::class.java -> this as T - else -> super.getCapability(capabilityClass) - } + if (capabilityClass == CustomTypeVariable::class.java) return this as T + + return super.getCapability(capabilityClass) } - override val isTypeVariable: Boolean = lowerBound.getConstructor() == upperBound.getConstructor() - && lowerBound.getConstructor().getDeclarationDescriptor() is TypeParameterDescriptor + override val isTypeVariable: Boolean = lowerBound.constructor == upperBound.constructor + && lowerBound.constructor.declarationDescriptor is TypeParameterDescriptor override fun substitutionResult(replacement: KotlinType): KotlinType { return if (replacement.isFlexible()) replacement @@ -323,7 +324,7 @@ class LazyJavaTypeResolver( // Int! >< Int? if (otherType.isFlexible()) return Specificity.Relation.DONT_KNOW // Int? >< Int! - if (otherType.isMarkedNullable()) return Specificity.Relation.DONT_KNOW + if (otherType.isMarkedNullable) return Specificity.Relation.DONT_KNOW // Int! lessSpecific Int return Specificity.Relation.LESS_SPECIFIC } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/dynamicTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/types/dynamicTypes.kt index d2cce6020c0..a881d0068c5 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/dynamicTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/dynamicTypes.kt @@ -43,19 +43,12 @@ object DynamicTypeFactory : FlexibleTypeFactory { return Impl(lowerBound, upperBound) } - private class Impl(lowerBound: KotlinType, upperBound: KotlinType) : DelegatingFlexibleType(lowerBound, upperBound, DynamicTypeFactory), Dynamicity, Specificity, NullAwareness, FlexibleTypeDelegation { - companion object { - internal val capabilityClasses = hashSetOf( - Dynamicity::class.java, - Specificity::class.java, - NullAwareness::class.java, - FlexibleTypeDelegation::class.java - ) - } + private class Impl(lowerBound: KotlinType, upperBound: KotlinType) : + DelegatingFlexibleType(lowerBound, upperBound, DynamicTypeFactory), Dynamicity { override fun getCapability(capabilityClass: Class): T? { @Suppress("UNCHECKED_CAST") - if (capabilityClass in capabilityClasses) return this as T + if (capabilityClass == Dynamicity::class.java) return this as T return super.getCapability(capabilityClass) } @@ -71,6 +64,6 @@ object DynamicTypeFactory : FlexibleTypeFactory { return createDynamicType(delegateType.builtIns) } - override fun computeIsNullable() = false + override fun isMarkedNullable() = false } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt index f8e3aacfab7..5c0722b060a 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt @@ -87,24 +87,19 @@ fun KotlinType.upperIfFlexible(): KotlinType = if (this.isFlexible()) this.flexi interface NullAwareness : TypeCapability { fun makeNullableAsSpecified(nullable: Boolean): KotlinType - fun computeIsNullable(): Boolean } -interface FlexibleTypeDelegation : TypeCapability { - val delegateType: KotlinType -} - -open class DelegatingFlexibleType protected constructor( +abstract class DelegatingFlexibleType protected constructor( override val lowerBound: KotlinType, override val upperBound: KotlinType, override val factory: FlexibleTypeFactory -) : DelegatingType(), NullAwareness, Flexibility, FlexibleTypeDelegation { +) : DelegatingType(), NullAwareness, Flexibility, Specificity { companion object { internal val capabilityClasses = hashSetOf( NullAwareness::class.java, Flexibility::class.java, SubtypingRepresentatives::class.java, - FlexibleTypeDelegation::class.java + Specificity::class.java ) @JvmField @@ -131,6 +126,8 @@ open class DelegatingFlexibleType protected constructor( } } + protected abstract val delegateType: KotlinType + override fun getCapability(capabilityClass: Class): T? { @Suppress("UNCHECKED_CAST") if (capabilityClass in capabilityClasses) return this as T @@ -143,17 +140,10 @@ open class DelegatingFlexibleType protected constructor( TypeUtils.makeNullableAsSpecified(upperBound, nullable)) } - override fun computeIsNullable() = delegateType.isMarkedNullable - - override fun isMarkedNullable(): Boolean = getCapability(NullAwareness::class.java)!!.computeIsNullable() - - override val delegateType: KotlinType - get() { - runAssertions() - return lowerBound - } - - override fun getDelegate() = getCapability(FlexibleTypeDelegation::class.java)!!.delegateType + final override fun getDelegate(): KotlinType { + runAssertions() + return delegateType + } override fun toString() = "('$lowerBound'..'$upperBound')" }