Refine naming: *TypeVariable -> *TypeParameter
This commit is contained in:
committed by
TeamCityServer
parent
7c3383bb39
commit
4733a0d970
+1
-1
@@ -285,7 +285,7 @@ class JavaNullabilityChecker(val upperBoundChecker: UpperBoundChecker) : Additio
|
||||
subType: KotlinType,
|
||||
superType: KotlinType
|
||||
): Boolean {
|
||||
if (superType !is NotNullTypeVariable || subType is NotNullTypeVariable) return false
|
||||
if (superType !is NotNullTypeParameter || subType is NotNullTypeParameter) return false
|
||||
return !AbstractNullabilityChecker.isSubtypeOfAny(
|
||||
createClassicTypeCheckerState(isErrorTypeEqualsToAnything = true),
|
||||
subType
|
||||
|
||||
+3
-5
@@ -44,8 +44,6 @@ import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.typeUtil.defaultProjections
|
||||
import org.jetbrains.kotlin.types.typeUtil.isDefaultBound
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
import java.lang.IllegalArgumentException
|
||||
import java.lang.IllegalStateException
|
||||
import java.util.*
|
||||
|
||||
open class ConstraintSystemBuilderImpl(private val mode: Mode = ConstraintSystemBuilderImpl.Mode.INFERENCE) : ConstraintSystem.Builder {
|
||||
@@ -310,9 +308,9 @@ open class ConstraintSystemBuilderImpl(private val mode: Mode = ConstraintSystem
|
||||
// Foo >: T!
|
||||
// both Foo and Foo? transform to Foo! here
|
||||
if (parameterType.isFlexible()) {
|
||||
val customTypeVariable = parameterType.getCustomTypeVariable()
|
||||
if (customTypeVariable != null) {
|
||||
newConstrainingType = customTypeVariable.substitutionResult(constrainingType)
|
||||
val customTypeParameter = parameterType.getCustomTypeParameter()
|
||||
if (customTypeParameter != null) {
|
||||
newConstrainingType = customTypeParameter.substitutionResult(constrainingType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -96,7 +96,7 @@ private fun checkExpressionArgument(
|
||||
val position = if (isReceiver) ReceiverConstraintPositionImpl(expressionArgument) else ArgumentConstraintPositionImpl(expressionArgument)
|
||||
|
||||
// Used only for arguments with @NotNull annotation
|
||||
if (expectedType is NotNullTypeVariable && argumentType.isMarkedNullable) {
|
||||
if (expectedType is NotNullTypeParameter && argumentType.isMarkedNullable) {
|
||||
diagnosticsHolder.addDiagnostic(ArgumentNullabilityMismatchDiagnostic(expectedType, argumentType, expressionArgument))
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -156,7 +156,7 @@ interface NewTypeSubstitutor : TypeSubstitutorMarker {
|
||||
if (type.isDefinitelyNotNullType) {
|
||||
replacement = replacement.makeDefinitelyNotNullOrNotNull()
|
||||
}
|
||||
if (type is CustomTypeVariable) {
|
||||
if (type is CustomTypeParameter) {
|
||||
replacement = type.substitutionResult(replacement).unwrap()
|
||||
}
|
||||
|
||||
|
||||
@@ -448,7 +448,7 @@ object AbstractTypeChecker {
|
||||
@OptIn(ObsoleteTypeKind::class)
|
||||
private fun TypeSystemContext.isCommonDenotableType(type: KotlinTypeMarker): Boolean =
|
||||
type.typeConstructor().isDenotable() &&
|
||||
!type.isDynamic() && !type.isDefinitelyNotNullType() && !type.isNotNullTypeVariable() &&
|
||||
!type.isDynamic() && !type.isDefinitelyNotNullType() && !type.isNotNullTypeParameter() &&
|
||||
type.lowerBoundIfFlexible().typeConstructor() == type.upperBoundIfFlexible().typeConstructor()
|
||||
|
||||
fun effectiveVariance(declared: TypeVariance, useSite: TypeVariance): TypeVariance? {
|
||||
@@ -704,7 +704,7 @@ object AbstractNullabilityChecker {
|
||||
|
||||
// i.e. subType is definitely not null
|
||||
@OptIn(ObsoleteTypeKind::class)
|
||||
if (subType.isDefinitelyNotNullType() || subType.isNotNullTypeVariable()) return true
|
||||
if (subType.isDefinitelyNotNullType() || subType.isNotNullTypeParameter()) return true
|
||||
|
||||
// i.e. subType is captured type, projection of which is marked not-null
|
||||
if (subType is CapturedTypeMarker && subType.isProjectionNotNull()) return true
|
||||
|
||||
@@ -380,7 +380,7 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
|
||||
// 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.isNotNullTypeParameter(): Boolean = false
|
||||
|
||||
fun KotlinTypeMarker.hasFlexibleNullability() =
|
||||
lowerBoundIfFlexible().isMarkedNullable() != upperBoundIfFlexible().isMarkedNullable()
|
||||
|
||||
+1
-1
@@ -254,7 +254,7 @@ private class SignatureParts(
|
||||
get() = TypeUtils.getClassDescriptor(this as KotlinType)?.let { DescriptorUtils.getFqName(it) }
|
||||
|
||||
override val KotlinTypeMarker.isNotNullTypeParameterCompat: Boolean
|
||||
get() = (this as KotlinType).unwrap() is NotNullTypeParameter
|
||||
get() = (this as KotlinType).unwrap() is NotNullTypeParameterImpl
|
||||
|
||||
override fun KotlinTypeMarker.isEqual(other: KotlinTypeMarker): Boolean =
|
||||
containerContext.components.kotlinTypeChecker.equalTypes(this as KotlinType, other as KotlinType)
|
||||
|
||||
+6
-7
@@ -34,7 +34,6 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext
|
||||
import org.jetbrains.kotlin.types.TypeRefinement
|
||||
import org.jetbrains.kotlin.types.typeUtil.createProjection
|
||||
import org.jetbrains.kotlin.types.typeUtil.isTypeParameter
|
||||
|
||||
@@ -166,7 +165,7 @@ class JavaTypeEnhancement(private val javaResolverSettings: JavaResolverSettings
|
||||
if (javaResolverSettings.correctNullabilityForNotNullTypeParameter)
|
||||
enhancedType.makeSimpleTypeDefinitelyNotNullOrNotNull(useCorrectedNullabilityForTypeParameters = true)
|
||||
else
|
||||
NotNullTypeParameter(enhancedType)
|
||||
NotNullTypeParameterImpl(enhancedType)
|
||||
}
|
||||
|
||||
private fun List<Annotations>.compositeAnnotationsOrSingle() = when (size) {
|
||||
@@ -224,9 +223,9 @@ private object EnhancedTypeAnnotationDescriptor : AnnotationDescriptor {
|
||||
override fun toString() = "[EnhancedType]"
|
||||
}
|
||||
|
||||
internal class NotNullTypeParameter(override val delegate: SimpleType) : NotNullTypeVariable, DelegatingSimpleType() {
|
||||
internal class NotNullTypeParameterImpl(override val delegate: SimpleType) : NotNullTypeParameter, DelegatingSimpleType() {
|
||||
|
||||
override val isTypeVariable: Boolean
|
||||
override val isTypeParameter: Boolean
|
||||
get() = true
|
||||
|
||||
override fun substitutionResult(replacement: KotlinType): KotlinType {
|
||||
@@ -250,13 +249,13 @@ internal class NotNullTypeParameter(override val delegate: SimpleType) : NotNull
|
||||
val result = makeNullableAsSpecified(false)
|
||||
if (!this.isTypeParameter()) return result
|
||||
|
||||
return NotNullTypeParameter(result)
|
||||
return NotNullTypeParameterImpl(result)
|
||||
}
|
||||
|
||||
override fun replaceAnnotations(newAnnotations: Annotations) = NotNullTypeParameter(delegate.replaceAnnotations(newAnnotations))
|
||||
override fun replaceAnnotations(newAnnotations: Annotations) = NotNullTypeParameterImpl(delegate.replaceAnnotations(newAnnotations))
|
||||
override fun makeNullableAsSpecified(newNullability: Boolean) =
|
||||
if (newNullability) delegate.makeNullableAsSpecified(true) else this
|
||||
|
||||
@TypeRefinement
|
||||
override fun replaceDelegate(delegate: SimpleType) = NotNullTypeParameter(delegate)
|
||||
override fun replaceDelegate(delegate: SimpleType) = NotNullTypeParameterImpl(delegate)
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ class LazyWrappedType(
|
||||
class DefinitelyNotNullType private constructor(
|
||||
val original: SimpleType,
|
||||
private val useCorrectedNullabilityForTypeParameters: Boolean
|
||||
) : DelegatingSimpleType(), CustomTypeVariable,
|
||||
) : DelegatingSimpleType(), CustomTypeParameter,
|
||||
DefinitelyNotNullTypeMarker {
|
||||
|
||||
companion object {
|
||||
@@ -161,7 +161,7 @@ class DefinitelyNotNullType private constructor(
|
||||
override val isMarkedNullable: Boolean
|
||||
get() = false
|
||||
|
||||
override val isTypeVariable: Boolean
|
||||
override val isTypeParameter: Boolean
|
||||
get() = delegate.constructor is NewTypeVariableConstructor ||
|
||||
delegate.constructor.declarationDescriptor is TypeParameterDescriptor
|
||||
|
||||
|
||||
@@ -18,24 +18,24 @@ package org.jetbrains.kotlin.types
|
||||
|
||||
|
||||
// To facilitate laziness, any KotlinType implementation may inherit from this trait,
|
||||
// even if it turns out that the type an instance represents is not actually a type variable
|
||||
// (i.e. it is not derived from a type parameter), see isTypeVariable
|
||||
interface CustomTypeVariable {
|
||||
val isTypeVariable: Boolean
|
||||
// even if it turns out that the type an instance represents is not actually a type parameter
|
||||
// (i.e. it is not derived from a type parameter), see isTypeParameter
|
||||
interface CustomTypeParameter {
|
||||
val isTypeParameter: Boolean
|
||||
|
||||
// Throws an exception when isTypeVariable == false
|
||||
// Throws an exception when isTypeParameter == false
|
||||
fun substitutionResult(replacement: KotlinType): KotlinType
|
||||
}
|
||||
|
||||
// That interface is needed to provide information about definitely not null
|
||||
// type parameters (e.g. from @NotNull annotation) to type system
|
||||
interface NotNullTypeVariable : CustomTypeVariable
|
||||
interface NotNullTypeParameter : CustomTypeParameter
|
||||
|
||||
fun KotlinType.isCustomTypeVariable(): Boolean = (unwrap() as? CustomTypeVariable)?.isTypeVariable ?: false
|
||||
fun KotlinType.getCustomTypeVariable(): CustomTypeVariable? =
|
||||
(unwrap() as? CustomTypeVariable)?.let {
|
||||
if (it.isTypeVariable) it else null
|
||||
}
|
||||
fun KotlinType.isCustomTypeParameter(): Boolean = (unwrap() as? CustomTypeParameter)?.isTypeParameter ?: false
|
||||
fun KotlinType.getCustomTypeParameter(): CustomTypeParameter? =
|
||||
(unwrap() as? CustomTypeParameter)?.let {
|
||||
if (it.isTypeParameter) it else null
|
||||
}
|
||||
|
||||
interface SubtypingRepresentatives {
|
||||
val subTypeRepresentative: KotlinType
|
||||
@@ -45,13 +45,13 @@ interface SubtypingRepresentatives {
|
||||
}
|
||||
|
||||
fun KotlinType.getSubtypeRepresentative(): KotlinType =
|
||||
(unwrap() as? SubtypingRepresentatives)?.subTypeRepresentative ?: this
|
||||
(unwrap() as? SubtypingRepresentatives)?.subTypeRepresentative ?: this
|
||||
|
||||
fun KotlinType.getSupertypeRepresentative(): KotlinType =
|
||||
(unwrap() as? SubtypingRepresentatives)?.superTypeRepresentative ?: this
|
||||
(unwrap() as? SubtypingRepresentatives)?.superTypeRepresentative ?: this
|
||||
|
||||
fun sameTypeConstructors(first: KotlinType, second: KotlinType): Boolean {
|
||||
return (first.unwrap() as? SubtypingRepresentatives)?.sameTypeConstructor(second) ?: false
|
||||
|| (second.unwrap() as? SubtypingRepresentatives)?.sameTypeConstructor(first) ?: false
|
||||
|| (second.unwrap() as? SubtypingRepresentatives)?.sameTypeConstructor(first) ?: false
|
||||
}
|
||||
|
||||
|
||||
@@ -208,7 +208,7 @@ public class TypeSubstitutor implements TypeSubstitutorMarker {
|
||||
null;
|
||||
|
||||
Variance originalProjectionKind = originalProjection.getProjectionKind();
|
||||
if (replacement == null && FlexibleTypesKt.isFlexible(type) && !TypeCapabilitiesKt.isCustomTypeVariable(type)) {
|
||||
if (replacement == null && FlexibleTypesKt.isFlexible(type) && !TypeCapabilitiesKt.isCustomTypeParameter(type)) {
|
||||
FlexibleType flexibleType = FlexibleTypesKt.asFlexibleType(type);
|
||||
TypeProjection substitutedLower =
|
||||
unsafeSubstitute(
|
||||
@@ -255,12 +255,12 @@ public class TypeSubstitutor implements TypeSubstitutorMarker {
|
||||
}
|
||||
}
|
||||
KotlinType substitutedType;
|
||||
CustomTypeVariable typeVariable = TypeCapabilitiesKt.getCustomTypeVariable(type);
|
||||
CustomTypeParameter customTypeParameter = TypeCapabilitiesKt.getCustomTypeParameter(type);
|
||||
if (replacement.isStarProjection()) {
|
||||
return replacement;
|
||||
}
|
||||
else if (typeVariable != null) {
|
||||
substitutedType = typeVariable.substitutionResult(replacement.getType());
|
||||
else if (customTypeParameter != null) {
|
||||
substitutedType = customTypeParameter.substitutionResult(replacement.getType());
|
||||
}
|
||||
else {
|
||||
// this is a simple type T or T?: if it's T, we should just take replacement, if T? - we make replacement nullable
|
||||
|
||||
@@ -151,7 +151,7 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
||||
}
|
||||
|
||||
@OptIn(ObsoleteTypeKind::class)
|
||||
override fun KotlinTypeMarker.isNotNullTypeVariable(): Boolean = this is NotNullTypeVariable
|
||||
override fun KotlinTypeMarker.isNotNullTypeParameter(): Boolean = this is NotNullTypeParameter
|
||||
|
||||
override fun SimpleTypeMarker.isMarkedNullable(): Boolean {
|
||||
require(this is SimpleType, this::errorMessage)
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.types.checker.ErrorTypesAreEqualToAnything
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
||||
import org.jetbrains.kotlin.types.TypeRefinement
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
|
||||
fun KotlinType.isFlexible(): Boolean = unwrap() is FlexibleType
|
||||
@@ -82,7 +81,7 @@ fun KotlinType.upperIfFlexible(): SimpleType = with(unwrap()) {
|
||||
}
|
||||
}
|
||||
|
||||
class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : FlexibleType(lowerBound, upperBound), CustomTypeVariable {
|
||||
class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : FlexibleType(lowerBound, upperBound), CustomTypeParameter {
|
||||
companion object {
|
||||
@JvmField
|
||||
var RUN_SLOW_ASSERTIONS = false
|
||||
@@ -114,7 +113,7 @@ class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : Flexibl
|
||||
return lowerBound
|
||||
}
|
||||
|
||||
override val isTypeVariable: Boolean
|
||||
override val isTypeParameter: Boolean
|
||||
get() = lowerBound.constructor.declarationDescriptor is TypeParameterDescriptor
|
||||
&& lowerBound.constructor == upperBound.constructor
|
||||
|
||||
|
||||
Reference in New Issue
Block a user