Fix formatting in flexibleTypes.kt
This commit is contained in:
@@ -45,10 +45,8 @@ fun KotlinType.isNullabilityFlexible(): Boolean {
|
|||||||
fun Collection<KotlinType>.singleBestRepresentative(): KotlinType? {
|
fun Collection<KotlinType>.singleBestRepresentative(): KotlinType? {
|
||||||
if (this.size == 1) return this.first()
|
if (this.size == 1) return this.first()
|
||||||
|
|
||||||
return this.firstOrNull {
|
return this.firstOrNull { candidate ->
|
||||||
candidate ->
|
this.all { other ->
|
||||||
this.all {
|
|
||||||
other ->
|
|
||||||
// We consider error types equal to anything here, so that intersections like
|
// We consider error types equal to anything here, so that intersections like
|
||||||
// {Array<String>, Array<[ERROR]>} work correctly
|
// {Array<String>, Array<[ERROR]>} work correctly
|
||||||
candidate == other || ErrorTypesAreEqualToAnything.equalTypes(candidate, other)
|
candidate == other || ErrorTypesAreEqualToAnything.equalTypes(candidate, other)
|
||||||
@@ -73,6 +71,7 @@ fun KotlinType.lowerIfFlexible(): SimpleType = with(unwrap()) {
|
|||||||
is SimpleType -> this
|
is SimpleType -> this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KotlinType.upperIfFlexible(): SimpleType = with(unwrap()) {
|
fun KotlinType.upperIfFlexible(): SimpleType = with(unwrap()) {
|
||||||
when (this) {
|
when (this) {
|
||||||
is FlexibleType -> upperBound
|
is FlexibleType -> upperBound
|
||||||
@@ -98,10 +97,10 @@ class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : Flexibl
|
|||||||
if (!RUN_SLOW_ASSERTIONS || assertionsDone) return
|
if (!RUN_SLOW_ASSERTIONS || assertionsDone) return
|
||||||
assertionsDone = true
|
assertionsDone = true
|
||||||
|
|
||||||
assert (!lowerBound.isFlexible()) { "Lower bound of a flexible type can not be flexible: $lowerBound" }
|
assert(!lowerBound.isFlexible()) { "Lower bound of a flexible type can not be flexible: $lowerBound" }
|
||||||
assert (!upperBound.isFlexible()) { "Upper bound of a flexible type can not be flexible: $upperBound" }
|
assert(!upperBound.isFlexible()) { "Upper bound of a flexible type can not be flexible: $upperBound" }
|
||||||
assert (lowerBound != upperBound) { "Lower and upper bounds are equal: $lowerBound == $upperBound" }
|
assert(lowerBound != upperBound) { "Lower and upper bounds are equal: $lowerBound == $upperBound" }
|
||||||
assert (KotlinTypeChecker.DEFAULT.isSubtypeOf(lowerBound, upperBound)) {
|
assert(KotlinTypeChecker.DEFAULT.isSubtypeOf(lowerBound, upperBound)) {
|
||||||
"Lower bound $lowerBound of a flexible type must be a subtype of the upper bound $upperBound"
|
"Lower bound $lowerBound of a flexible type must be a subtype of the upper bound $upperBound"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,19 +111,20 @@ class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : Flexibl
|
|||||||
return lowerBound
|
return lowerBound
|
||||||
}
|
}
|
||||||
|
|
||||||
override val isTypeVariable: Boolean get() = lowerBound.constructor.declarationDescriptor is TypeParameterDescriptor
|
override val isTypeVariable: Boolean
|
||||||
&& lowerBound.constructor == upperBound.constructor
|
get() = lowerBound.constructor.declarationDescriptor is TypeParameterDescriptor
|
||||||
|
&& lowerBound.constructor == upperBound.constructor
|
||||||
|
|
||||||
override fun substitutionResult(replacement: KotlinType): KotlinType {
|
override fun substitutionResult(replacement: KotlinType): KotlinType {
|
||||||
val unwrapped = replacement.unwrap()
|
val unwrapped = replacement.unwrap()
|
||||||
return when(unwrapped) {
|
return when (unwrapped) {
|
||||||
is FlexibleType -> unwrapped
|
is FlexibleType -> unwrapped
|
||||||
is SimpleType -> KotlinTypeFactory.flexibleType(unwrapped, unwrapped.makeNullableAsSpecified(true))
|
is SimpleType -> KotlinTypeFactory.flexibleType(unwrapped, unwrapped.makeNullableAsSpecified(true))
|
||||||
}.inheritEnhancement(unwrapped)
|
}.inheritEnhancement(unwrapped)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun replaceAnnotations(newAnnotations: Annotations): UnwrappedType
|
override fun replaceAnnotations(newAnnotations: Annotations): UnwrappedType =
|
||||||
= KotlinTypeFactory.flexibleType(lowerBound.replaceAnnotations(newAnnotations), upperBound.replaceAnnotations(newAnnotations))
|
KotlinTypeFactory.flexibleType(lowerBound.replaceAnnotations(newAnnotations), upperBound.replaceAnnotations(newAnnotations))
|
||||||
|
|
||||||
override fun render(renderer: DescriptorRenderer, options: DescriptorRendererOptions): String {
|
override fun render(renderer: DescriptorRenderer, options: DescriptorRendererOptions): String {
|
||||||
if (options.debugMode) {
|
if (options.debugMode) {
|
||||||
@@ -133,8 +133,10 @@ class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : Flexibl
|
|||||||
return renderer.renderFlexibleType(renderer.renderType(lowerBound), renderer.renderType(upperBound), builtIns)
|
return renderer.renderFlexibleType(renderer.renderType(lowerBound), renderer.renderType(upperBound), builtIns)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun makeNullableAsSpecified(newNullability: Boolean): UnwrappedType
|
override fun makeNullableAsSpecified(newNullability: Boolean): UnwrappedType = KotlinTypeFactory.flexibleType(
|
||||||
= KotlinTypeFactory.flexibleType(lowerBound.makeNullableAsSpecified(newNullability), upperBound.makeNullableAsSpecified(newNullability))
|
lowerBound.makeNullableAsSpecified(newNullability),
|
||||||
|
upperBound.makeNullableAsSpecified(newNullability)
|
||||||
|
)
|
||||||
|
|
||||||
@TypeRefinement
|
@TypeRefinement
|
||||||
@OptIn(TypeRefinement::class)
|
@OptIn(TypeRefinement::class)
|
||||||
|
|||||||
Reference in New Issue
Block a user