Fix creating of refined FlexibleType and RawType
There was an issue that `KotlinType.equals` called in `KotlinTypeFactory.flexibleType` and `RawType` constructor produced endless recursion of types that wasn't computed yet
This commit is contained in:
committed by
Dmitry Savvinov
parent
33a31fb688
commit
b477184a3c
@@ -32,10 +32,16 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
|||||||
import org.jetbrains.kotlin.types.refinement.TypeRefinement
|
import org.jetbrains.kotlin.types.refinement.TypeRefinement
|
||||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||||
|
|
||||||
class RawTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : FlexibleType(lowerBound, upperBound), RawType {
|
class RawTypeImpl private constructor(lowerBound: SimpleType, upperBound: SimpleType, disableAssertion: Boolean) :
|
||||||
|
FlexibleType(lowerBound, upperBound), RawType {
|
||||||
|
|
||||||
|
constructor(lowerBound: SimpleType, upperBound: SimpleType) : this(lowerBound, upperBound, false)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
assert(KotlinTypeChecker.DEFAULT.isSubtypeOf(lowerBound, upperBound)) {
|
if (!disableAssertion) {
|
||||||
"Lower bound $lowerBound of a flexible type must be a subtype of the upper bound $upperBound"
|
assert(KotlinTypeChecker.DEFAULT.isSubtypeOf(lowerBound, upperBound)) {
|
||||||
|
"Lower bound $lowerBound of a flexible type must be a subtype of the upper bound $upperBound"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +93,11 @@ class RawTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : FlexibleType
|
|||||||
@TypeRefinement
|
@TypeRefinement
|
||||||
@UseExperimental(TypeRefinement::class)
|
@UseExperimental(TypeRefinement::class)
|
||||||
override fun refine(kotlinTypeRefiner: KotlinTypeRefiner): FlexibleType {
|
override fun refine(kotlinTypeRefiner: KotlinTypeRefiner): FlexibleType {
|
||||||
return RawTypeImpl(kotlinTypeRefiner.refineType(lowerBound) as SimpleType, kotlinTypeRefiner.refineType(upperBound) as SimpleType)
|
return RawTypeImpl(
|
||||||
|
kotlinTypeRefiner.refineType(lowerBound) as SimpleType,
|
||||||
|
kotlinTypeRefiner.refineType(upperBound) as SimpleType,
|
||||||
|
disableAssertion = true
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -139,9 +139,10 @@ class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : Flexibl
|
|||||||
|
|
||||||
@TypeRefinement
|
@TypeRefinement
|
||||||
@UseExperimental(TypeRefinement::class)
|
@UseExperimental(TypeRefinement::class)
|
||||||
override fun refine(kotlinTypeRefiner: KotlinTypeRefiner) =
|
override fun refine(kotlinTypeRefiner: KotlinTypeRefiner): FlexibleType {
|
||||||
KotlinTypeFactory.flexibleType(
|
return FlexibleTypeImpl(
|
||||||
kotlinTypeRefiner.refineType(lowerBound) as SimpleType,
|
kotlinTypeRefiner.refineType(lowerBound) as SimpleType,
|
||||||
kotlinTypeRefiner.refineType(upperBound) as SimpleType
|
kotlinTypeRefiner.refineType(upperBound) as SimpleType
|
||||||
) as FlexibleType
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user