Add assertion into DynamicTypeFactory about type range.

This commit is contained in:
Stanislav Erokhin
2016-04-22 19:32:33 +03:00
parent 8f32eeb663
commit ca74f0d86e
2 changed files with 11 additions and 2 deletions
@@ -88,6 +88,9 @@ public class CommonSupertypes {
Set<FlexibleTypeFactory> factories = new LinkedHashSet<FlexibleTypeFactory>();
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());
@@ -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) :