Fix formatting in flexibleTypes.kt

This commit is contained in:
Victor Petukhov
2020-12-01 17:15:56 +03:00
parent 8e5bcd349e
commit 1ccbb09029
@@ -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
@@ -112,7 +111,8 @@ 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
get() = lowerBound.constructor.declarationDescriptor is TypeParameterDescriptor
&& lowerBound.constructor == upperBound.constructor && lowerBound.constructor == upperBound.constructor
override fun substitutionResult(replacement: KotlinType): KotlinType { override fun substitutionResult(replacement: KotlinType): KotlinType {
@@ -123,8 +123,8 @@ class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : Flexibl
}.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)