mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-10 08:31:29 +00:00
[common] fix flexible type approximation in renders
^KTIJ-3030 Fixed (cherry picked from commit 4855d88a9f6fbce9aeeea6fe1f29dd099a833aed) KT-CR-2373
This commit is contained in:
committed by
Nikita Bobko
parent
958b0ff24a
commit
a8a6f51a0e
@@ -32,7 +32,9 @@ private fun KotlinType.approximateNonDynamicFlexibleTypes(
|
||||
|
||||
if (isFlexible()) {
|
||||
val flexible = asFlexibleType()
|
||||
val lowerClass = flexible.lowerBound.constructor.declarationDescriptor as? ClassDescriptor?
|
||||
val lowerBound = flexible.lowerBound
|
||||
val upperBound = flexible.upperBound
|
||||
val lowerClass = lowerBound.constructor.declarationDescriptor as? ClassDescriptor?
|
||||
val isCollection = lowerClass != null && JavaToKotlinClassMapper.isMutable(lowerClass)
|
||||
// (Mutable)Collection<T>! -> MutableCollection<T>?
|
||||
// Foo<(Mutable)Collection<T>!>! -> Foo<Collection<T>>?
|
||||
@@ -40,17 +42,21 @@ private fun KotlinType.approximateNonDynamicFlexibleTypes(
|
||||
// Foo<Bar!>! -> Foo<Bar>?
|
||||
var approximation =
|
||||
if (isCollection)
|
||||
flexible.lowerBound.makeNullableAsSpecified(!preferNotNull)
|
||||
else
|
||||
if (this is RawType && preferStarForRaw) flexible.upperBound.makeNullableAsSpecified(!preferNotNull)
|
||||
// (Mutable)Collection<T>!
|
||||
if (lowerBound.isMarkedNullable != upperBound.isMarkedNullable)
|
||||
lowerBound.makeNullableAsSpecified(!preferNotNull)
|
||||
else
|
||||
if (preferNotNull) flexible.lowerBound else flexible.upperBound
|
||||
lowerBound
|
||||
else
|
||||
if (this is RawType && preferStarForRaw) upperBound.makeNullableAsSpecified(!preferNotNull)
|
||||
else
|
||||
if (preferNotNull) lowerBound else upperBound
|
||||
|
||||
approximation = approximation.approximateNonDynamicFlexibleTypes()
|
||||
|
||||
approximation = if (nullability() == TypeNullability.NOT_NULL) approximation.makeNullableAsSpecified(false) else approximation
|
||||
|
||||
if (approximation.isMarkedNullable && !flexible.lowerBound
|
||||
if (approximation.isMarkedNullable && !lowerBound
|
||||
.isMarkedNullable && TypeUtils.isTypeParameter(approximation) && TypeUtils.hasNullableSuperType(approximation)
|
||||
) {
|
||||
approximation = approximation.makeNullableAsSpecified(false)
|
||||
|
||||
Reference in New Issue
Block a user