Report warnings on overrides with wrong types nullability

^KT-48899 Fixed
This commit is contained in:
Denis.Zharkov
2021-09-24 16:33:07 +03:00
committed by TeamCityServer
parent ec97dab6cd
commit f7ef551f99
29 changed files with 672 additions and 42 deletions
@@ -445,9 +445,10 @@ object AbstractTypeChecker {
return true
}
@OptIn(ObsoleteTypeKind::class)
private fun TypeSystemContext.isCommonDenotableType(type: KotlinTypeMarker): Boolean =
type.typeConstructor().isDenotable() &&
!type.isDynamic() && !type.isDefinitelyNotNullType() &&
!type.isDynamic() && !type.isDefinitelyNotNullType() && !type.isNotNullTypeVariable() &&
type.lowerBoundIfFlexible().typeConstructor() == type.upperBoundIfFlexible().typeConstructor()
fun effectiveVariance(declared: TypeVariance, useSite: TypeVariance): TypeVariance? {
@@ -702,7 +703,8 @@ object AbstractNullabilityChecker {
if (superType.isMarkedNullable()) return true
// i.e. subType is definitely not null
if (subType.isDefinitelyNotNullType()) return true
@OptIn(ObsoleteTypeKind::class)
if (subType.isDefinitelyNotNullType() || subType.isNotNullTypeVariable()) return true
// i.e. subType is captured type, projection of which is marked not-null
if (subType is CapturedTypeMarker && subType.isProjectionNotNull()) return true
@@ -377,6 +377,11 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
fun KotlinTypeMarker.isDefinitelyNotNullType(): Boolean = asSimpleType()?.asDefinitelyNotNullType() != null
// This kind of types is obsolete (expected to be removed at 1.7) and shouldn't be used further in a new code
// Now, such types are being replaced with definitely non-nullable types
@ObsoleteTypeKind
fun KotlinTypeMarker.isNotNullTypeVariable(): Boolean = false
fun KotlinTypeMarker.hasFlexibleNullability() =
lowerBoundIfFlexible().isMarkedNullable() != upperBoundIfFlexible().isMarkedNullable()
@@ -495,3 +500,6 @@ fun requireOrDescribe(condition: Boolean, value: Any?) {
"Unexpected: value = '$value'$typeInfo"
}
}
@RequiresOptIn("This kinds of type is obsolete and should not be used until you really need it")
annotation class ObsoleteTypeKind