Inference: Respect stub-type nullability in common super-type
This commit is contained in:
committed by
teamcity
parent
19a9091966
commit
5efbd016bd
+9
-4
@@ -86,12 +86,13 @@ object NewCommonSuperTypeCalculator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// i.e. result type also should be marked nullable
|
// i.e. result type also should be marked nullable
|
||||||
val notAllNotNull =
|
val allNotNull = types.all {
|
||||||
types.any { !isTypeVariable(it) && !AbstractNullabilityChecker.isSubtypeOfAny(stateStubTypesEqualToAnything, it) }
|
isTypeVariable(it) || isNotNullStubTypeForBuilderInference(it) || AbstractNullabilityChecker.isSubtypeOfAny(stateStubTypesEqualToAnything, it)
|
||||||
val notNullTypes = if (notAllNotNull) types.map { it.withNullability(false) } else types
|
}
|
||||||
|
val notNullTypes = if (!allNotNull) types.map { it.withNullability(false) } else types
|
||||||
|
|
||||||
val commonSuperType = commonSuperTypeForNotNullTypes(notNullTypes, depth, stateStubTypesEqualToAnything, stateStubTypesNotEqual)
|
val commonSuperType = commonSuperTypeForNotNullTypes(notNullTypes, depth, stateStubTypesEqualToAnything, stateStubTypesNotEqual)
|
||||||
return if (notAllNotNull)
|
return if (!allNotNull)
|
||||||
refineNullabilityForUndefinedNullability(types, commonSuperType) ?: commonSuperType.withNullability(true)
|
refineNullabilityForUndefinedNullability(types, commonSuperType) ?: commonSuperType.withNullability(true)
|
||||||
else
|
else
|
||||||
commonSuperType
|
commonSuperType
|
||||||
@@ -207,6 +208,10 @@ object NewCommonSuperTypeCalculator {
|
|||||||
return type.isStubTypeForVariableInSubtyping() || isCapturedTypeVariable(type)
|
return type.isStubTypeForVariableInSubtyping() || isCapturedTypeVariable(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun TypeSystemCommonSuperTypesContext.isNotNullStubTypeForBuilderInference(type: SimpleTypeMarker): Boolean {
|
||||||
|
return type.isStubTypeForBuilderInference() && !type.isMarkedNullable()
|
||||||
|
}
|
||||||
|
|
||||||
private fun TypeSystemCommonSuperTypesContext.isCapturedTypeVariable(type: SimpleTypeMarker): Boolean {
|
private fun TypeSystemCommonSuperTypesContext.isCapturedTypeVariable(type: SimpleTypeMarker): Boolean {
|
||||||
val projectedType =
|
val projectedType =
|
||||||
type.asCapturedType()?.typeConstructor()?.projection()?.takeUnless { it.isStarProjection() }?.getType() ?: return false
|
type.asCapturedType()?.typeConstructor()?.projection()?.takeUnless { it.isStarProjection() }?.getType() ?: return false
|
||||||
|
|||||||
Reference in New Issue
Block a user