[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
+12
-6
@@ -32,7 +32,9 @@ private fun KotlinType.approximateNonDynamicFlexibleTypes(
|
|||||||
|
|
||||||
if (isFlexible()) {
|
if (isFlexible()) {
|
||||||
val flexible = asFlexibleType()
|
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)
|
val isCollection = lowerClass != null && JavaToKotlinClassMapper.isMutable(lowerClass)
|
||||||
// (Mutable)Collection<T>! -> MutableCollection<T>?
|
// (Mutable)Collection<T>! -> MutableCollection<T>?
|
||||||
// Foo<(Mutable)Collection<T>!>! -> Foo<Collection<T>>?
|
// Foo<(Mutable)Collection<T>!>! -> Foo<Collection<T>>?
|
||||||
@@ -40,17 +42,21 @@ private fun KotlinType.approximateNonDynamicFlexibleTypes(
|
|||||||
// Foo<Bar!>! -> Foo<Bar>?
|
// Foo<Bar!>! -> Foo<Bar>?
|
||||||
var approximation =
|
var approximation =
|
||||||
if (isCollection)
|
if (isCollection)
|
||||||
flexible.lowerBound.makeNullableAsSpecified(!preferNotNull)
|
// (Mutable)Collection<T>!
|
||||||
else
|
if (lowerBound.isMarkedNullable != upperBound.isMarkedNullable)
|
||||||
if (this is RawType && preferStarForRaw) flexible.upperBound.makeNullableAsSpecified(!preferNotNull)
|
lowerBound.makeNullableAsSpecified(!preferNotNull)
|
||||||
else
|
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 = approximation.approximateNonDynamicFlexibleTypes()
|
||||||
|
|
||||||
approximation = if (nullability() == TypeNullability.NOT_NULL) approximation.makeNullableAsSpecified(false) else approximation
|
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)
|
.isMarkedNullable && TypeUtils.isTypeParameter(approximation) && TypeUtils.hasNullableSuperType(approximation)
|
||||||
) {
|
) {
|
||||||
approximation = approximation.makeNullableAsSpecified(false)
|
approximation = approximation.makeNullableAsSpecified(false)
|
||||||
|
|||||||
Reference in New Issue
Block a user