Do subtyping with stub types properly
1) Return stub type if we are calculating super type between two same stub types 2) Return nullable Any if those stub types are different
This commit is contained in:
@@ -478,7 +478,11 @@ object AbstractTypeChecker {
|
||||
)
|
||||
}
|
||||
|
||||
if (subType.isStubType() || superType.isStubType()) return context.isStubTypeEqualsToAnything
|
||||
if (subType.isStubType() && superType.isStubType())
|
||||
return subType.typeConstructor() === superType.typeConstructor()
|
||||
|
||||
if (subType.isStubType() || superType.isStubType() || subType.isStubTypeForVariableInSubtyping() || superType.isStubTypeForVariableInSubtyping())
|
||||
return context.isStubTypeEqualsToAnything
|
||||
|
||||
// superType might be a definitely notNull type (see KT-42824)
|
||||
val superOriginalType = superType.asDefinitelyNotNullType()?.original() ?: superType
|
||||
@@ -742,7 +746,7 @@ object AbstractNullabilityChecker {
|
||||
if (type.isNothing()) return true
|
||||
if (type.isMarkedNullable()) return false
|
||||
|
||||
if (context.isStubTypeEqualsToAnything && type.isStubType()) return true
|
||||
if (context.isStubTypeEqualsToAnything && (type.isStubTypeForVariableInSubtyping() || type.isStubType())) return true
|
||||
|
||||
return areEqualTypeConstructors(type.typeConstructor(), end)
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ interface TypeSystemBuiltInsContext {
|
||||
/**
|
||||
* Context that allow construction of types
|
||||
*/
|
||||
interface TypeSystemTypeFactoryContext {
|
||||
interface TypeSystemTypeFactoryContext: TypeSystemBuiltInsContext {
|
||||
fun createFlexibleType(lowerBound: SimpleTypeMarker, upperBound: SimpleTypeMarker): KotlinTypeMarker
|
||||
fun createSimpleType(
|
||||
constructor: TypeConstructorMarker,
|
||||
@@ -169,7 +169,7 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
|
||||
): CapturedTypeMarker
|
||||
|
||||
fun createStubType(typeVariable: TypeVariableMarker): StubTypeMarker
|
||||
|
||||
fun createStubTypeForTypeVariablesInSubtyping(typeVariable: TypeVariableMarker): StubTypeMarker
|
||||
|
||||
fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker
|
||||
fun KotlinTypeMarker.removeExactAnnotation(): KotlinTypeMarker
|
||||
@@ -299,6 +299,7 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
|
||||
}
|
||||
|
||||
fun SimpleTypeMarker.isStubType(): Boolean
|
||||
fun SimpleTypeMarker.isStubTypeForVariableInSubtyping(): Boolean
|
||||
|
||||
fun KotlinTypeMarker.asTypeArgument(): TypeArgumentMarker
|
||||
|
||||
|
||||
Reference in New Issue
Block a user