diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/CommonSupertypes.java b/compiler/frontend/src/org/jetbrains/kotlin/types/CommonSupertypes.java index d2c6604eff6..cfbf9ac27ec 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/CommonSupertypes.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/CommonSupertypes.java @@ -88,6 +88,9 @@ public class CommonSupertypes { Set factories = new LinkedHashSet(); for (KotlinType type : types) { if (FlexibleTypesKt.isFlexible(type)) { + if (DynamicTypesKt.isDynamic(type)) { + return type; + } hasFlexible = true; Flexibility flexibility = FlexibleTypesKt.flexibility(type); upper.add(flexibility.getUpperBound()); diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/dynamicTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/types/dynamicTypes.kt index 9af00bdd855..d72bdcb3f6e 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/dynamicTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/dynamicTypes.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.types import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.types.Flexibility.SpecificityRelation +import org.jetbrains.kotlin.types.checker.KotlinTypeChecker import org.jetbrains.kotlin.types.typeUtil.builtIns open class DynamicTypesSettings { @@ -40,8 +41,13 @@ object DynamicTypeFactory : FlexibleTypeFactory { override val id: String get() = "kotlin.DynamicType" override fun create(lowerBound: KotlinType, upperBound: KotlinType): KotlinType { - if (lowerBound == upperBound) return lowerBound - return Impl(lowerBound, upperBound) + if (KotlinTypeChecker.FLEXIBLE_UNEQUAL_TO_INFLEXIBLE.equalTypes(lowerBound, lowerBound.builtIns.nothingType) && + KotlinTypeChecker.FLEXIBLE_UNEQUAL_TO_INFLEXIBLE.equalTypes(upperBound, upperBound.builtIns.nullableAnyType)) { + return Impl(lowerBound, upperBound) + } + else { + throw IllegalStateException("Illegal type range for dynamic type: $lowerBound..$upperBound") + } } private class Impl(lowerBound: KotlinType, upperBound: KotlinType) :