Take into account SimpleTypeWithEnhancement and subtyping related places

^KT-47854 Fixed
This commit is contained in:
Victor Petukhov
2021-07-29 12:54:15 +03:00
committed by teamcityserver
parent 6ab632f6ad
commit 3eaa452f9e
4 changed files with 9 additions and 5 deletions
@@ -14,4 +14,4 @@ import org.jspecify.nullness.Nullable;
public interface J2<V extends @Nullable Object> extends J1<V> { }
// FILE: kotlin.kt
private fun J2<*>.bar() = J1.foo(this)
private fun J2<*>.bar() = J1.foo(this)
@@ -1,4 +1,5 @@
// JSPECIFY_STATE: warn
// !LANGUAGE: +TypeEnhancementImprovementsInStrictMode
// FILE: J1.java
import org.jetbrains.annotations.Nullable;
@@ -13,4 +14,4 @@ import org.jspecify.nullness.Nullable;
public interface J2<V extends @Nullable Object> extends J1<V> { }
// FILE: kotlin.kt
private fun J2<*>.bar() = J1.foo(this)
private fun J2<*>.bar() = J1.foo(this)
@@ -33,7 +33,7 @@ class SimpleTypeWithEnhancement(
) : DelegatingSimpleType(),
TypeWithEnhancement {
override val origin: UnwrappedType get() = delegate
override val origin get() = delegate
override fun replaceAnnotations(newAnnotations: Annotations): SimpleType =
origin.replaceAnnotations(newAnnotations).wrapEnhancement(enhancement) as SimpleType
@@ -142,7 +142,7 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
override fun SimpleTypeMarker.asCapturedType(): CapturedTypeMarker? {
require(this is SimpleType, this::errorMessage)
return this as? NewCapturedType
return if (this is SimpleTypeWithEnhancement) origin.asCapturedType() else this as? NewCapturedType
}
override fun SimpleTypeMarker.asDefinitelyNotNullType(): DefinitelyNotNullTypeMarker? {
@@ -326,9 +326,12 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
require(this is SimpleType, this::errorMessage)
return !isError &&
constructor.declarationDescriptor !is TypeAliasDescriptor &&
(constructor.declarationDescriptor != null || this is CapturedType || this is NewCapturedType || this is DefinitelyNotNullType || constructor is IntegerLiteralTypeConstructor)
(constructor.declarationDescriptor != null || this is CapturedType || this is NewCapturedType || this is DefinitelyNotNullType || constructor is IntegerLiteralTypeConstructor || isSingleClassifierTypeWithEnhancement())
}
private fun SimpleTypeMarker.isSingleClassifierTypeWithEnhancement() =
this is SimpleTypeWithEnhancement && origin.isSingleClassifierType()
override fun KotlinTypeMarker.contains(predicate: (KotlinTypeMarker) -> Boolean): Boolean {
require(this is KotlinType, this::errorMessage)
return containsInternal(this, predicate)