From f405b3f8270cfd8369b0b2cb89e4582131c20e77 Mon Sep 17 00:00:00 2001 From: "simon.ogorodnik" Date: Wed, 26 Feb 2020 16:38:15 +0300 Subject: [PATCH] [FIR] Reorganize ConeKotlinTypeProjection hierarchy --- .../jetbrains/kotlin/fir/types/ConeTypes.kt | 39 +++++++++---------- .../kotlin/fir/types/TypeRenderer.kt | 2 +- .../jetbrains/kotlin/fir/types/impl/Impl.kt | 4 +- .../jetbrains/kotlin/fir/dump/HtmlFirDump.kt | 5 +-- .../kotlin/fir/backend/ConversionUtils.kt | 2 +- .../kotlin/fir/backend/Fir2IrVisitor.kt | 2 +- .../kotlin/fir/java/FirJavaElementFinder.kt | 6 +-- .../jetbrains/kotlin/fir/java/JavaUtils.kt | 8 ++-- .../deserialization/FirTypeDeserializer.kt | 2 +- .../kotlin/fir/resolve/ResolveUtils.kt | 12 +++--- .../kotlin/fir/resolve/SamResolution.kt | 2 +- .../kotlin/fir/resolve/SupertypeUtils.kt | 4 +- .../kotlin/fir/resolve/calls/ResolverParts.kt | 2 +- .../resolve/inference/PostponedArguments.kt | 8 ++-- .../fir/resolve/substitution/Substitutors.kt | 10 ++--- .../FirExpressionsResolveTransformer.kt | 2 +- .../jetbrains/kotlin/fir/types/ArrayUtils.kt | 2 +- .../kotlin/fir/types/ConeInferenceContext.kt | 8 ++-- .../kotlin/fir/types/ConeTypeContext.kt | 12 +++--- .../jetbrains/kotlin/fir/types/TypeUtils.kt | 8 ++-- .../types/impl/ConeTypeParameterTypeImpl.kt | 4 +- .../types/impl/FirImplicitBuiltinTypeRef.kt | 6 +-- 22 files changed, 72 insertions(+), 78 deletions(-) diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt index 8c6dab67a1d..91c24e9bb6b 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt @@ -25,27 +25,25 @@ enum class ProjectionKind { } } -sealed class ConeKotlinTypeProjection : TypeArgumentMarker { +sealed class ConeTypeProjection : TypeArgumentMarker { abstract val kind: ProjectionKind companion object { - val EMPTY_ARRAY = arrayOf() + val EMPTY_ARRAY = arrayOf() } } -object ConeStarProjection : ConeKotlinTypeProjection() { +object ConeStarProjection : ConeTypeProjection() { override val kind: ProjectionKind get() = ProjectionKind.STAR } -data class ConeKotlinTypeProjectionIn(override val type: ConeKotlinType) : ConeKotlinTypeProjection(), - ConeTypedProjection { +data class ConeKotlinTypeProjectionIn(override val type: ConeKotlinType) : ConeKotlinTypeProjection() { override val kind: ProjectionKind get() = ProjectionKind.IN } -data class ConeKotlinTypeProjectionOut(override val type: ConeKotlinType) : ConeKotlinTypeProjection(), - ConeTypedProjection { +data class ConeKotlinTypeProjectionOut(override val type: ConeKotlinType) : ConeKotlinTypeProjection() { override val kind: ProjectionKind get() = ProjectionKind.OUT } @@ -53,13 +51,12 @@ data class ConeKotlinTypeProjectionOut(override val type: ConeKotlinType) : Cone // We assume type IS an invariant type projection to prevent additional wrapper here // (more exactly, invariant type projection contains type) sealed class ConeKotlinType : ConeKotlinTypeProjection(), - ConeTypedProjection, KotlinTypeMarker, TypeArgumentListMarker { override val kind: ProjectionKind get() = ProjectionKind.INVARIANT - abstract val typeArguments: Array + abstract val typeArguments: Array override val type: ConeKotlinType get() = this @@ -73,8 +70,8 @@ sealed class ConeKotlinType : ConeKotlinTypeProjection(), sealed class ConeSimpleKotlinType : ConeKotlinType(), SimpleTypeMarker -interface ConeTypedProjection { - val type: ConeKotlinType +sealed class ConeKotlinTypeProjection : ConeTypeProjection() { + abstract val type: ConeKotlinType } typealias ConeKotlinErrorType = ConeClassErrorType @@ -85,7 +82,7 @@ class ConeClassErrorType(val reason: String) : ConeClassLikeType() { override val lookupTag: ConeClassLikeLookupTag get() = ConeClassLikeErrorLookupTag(ClassId.fromString("")) - override val typeArguments: Array + override val typeArguments: Array get() = EMPTY_ARRAY override val nullability: ConeNullability @@ -109,7 +106,7 @@ open class ConeFlexibleType(val lowerBound: ConeKotlinType, val upperBound: Cone require(upperBound is SimpleTypeMarker, message) } - override val typeArguments: Array + override val typeArguments: Array get() = emptyArray() override val nullability: ConeNullability @@ -139,7 +136,7 @@ fun ConeKotlinType.upperBoundIfFlexible() = (this as? ConeFlexibleType)?.upperBo fun ConeKotlinType.lowerBoundIfFlexible() = (this as? ConeFlexibleType)?.lowerBound ?: this class ConeCapturedTypeConstructor( - val projection: ConeKotlinTypeProjection, + val projection: ConeTypeProjection, var supertypes: List? = null, val typeParameterMarker: TypeParameterMarker? = null ) : CapturedTypeConstructorMarker @@ -151,7 +148,7 @@ class ConeCapturedType( val constructor: ConeCapturedTypeConstructor ) : ConeSimpleKotlinType(), CapturedTypeMarker { constructor( - captureStatus: CaptureStatus, lowerType: ConeKotlinType?, projection: ConeKotlinTypeProjection, + captureStatus: CaptureStatus, lowerType: ConeKotlinType?, projection: ConeTypeProjection, typeParameterMarker: TypeParameterMarker ) : this( captureStatus, @@ -162,7 +159,7 @@ class ConeCapturedType( ) ) - override val typeArguments: Array + override val typeArguments: Array get() = emptyArray() } @@ -170,11 +167,11 @@ data class ConeTypeVariableType( override val nullability: ConeNullability, override val lookupTag: ConeClassifierLookupTag ) : ConeLookupTagBasedType() { - override val typeArguments: Array get() = emptyArray() + override val typeArguments: Array get() = emptyArray() } data class ConeDefinitelyNotNullType(val original: ConeKotlinType) : ConeSimpleKotlinType(), DefinitelyNotNullTypeMarker { - override val typeArguments: Array + override val typeArguments: Array get() = original.typeArguments override val nullability: ConeNullability get() = ConeNullability.NOT_NULL @@ -193,7 +190,7 @@ class ConeRawType(lowerBound: ConeKotlinType, upperBound: ConeKotlinType) : Cone class ConeIntersectionType( val intersectedTypes: Collection ) : ConeSimpleKotlinType(), TypeConstructorMarker { - override val typeArguments: Array + override val typeArguments: Array get() = emptyArray() override val nullability: ConeNullability @@ -205,7 +202,7 @@ fun ConeIntersectionType.mapTypes(func: (ConeKotlinType) -> ConeKotlinType): Con } class ConeStubType(val variable: ConeTypeVariable, override val nullability: ConeNullability) : StubTypeMarker, ConeSimpleKotlinType() { - override val typeArguments: Array + override val typeArguments: Array get() = emptyArray() } @@ -226,7 +223,7 @@ abstract class ConeIntegerLiteralType(val value: Long) : ConeSimpleKotlinType(), abstract val possibleTypes: Collection abstract val supertypes: List - override val typeArguments: Array = emptyArray() + override val typeArguments: Array = emptyArray() override val nullability: ConeNullability = ConeNullability.NOT_NULL abstract fun getApproximatedType(expectedType: ConeKotlinType? = null): ConeClassLikeType diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/TypeRenderer.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/TypeRenderer.kt index f61c5f0a9e3..d3e9fe828d3 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/TypeRenderer.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/TypeRenderer.kt @@ -50,7 +50,7 @@ fun ConeKotlinType.render(): String { } + nullabilitySuffix } -private fun ConeKotlinTypeProjection.render(): String { +private fun ConeTypeProjection.render(): String { return when (this) { ConeStarProjection -> "*" is ConeKotlinTypeProjectionIn -> "in ${type.render()}" diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/impl/Impl.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/impl/Impl.kt index b9d963098d5..2154769e817 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/impl/Impl.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/impl/Impl.kt @@ -7,12 +7,12 @@ package org.jetbrains.kotlin.fir.types.impl import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag import org.jetbrains.kotlin.fir.types.ConeClassLikeType -import org.jetbrains.kotlin.fir.types.ConeKotlinTypeProjection +import org.jetbrains.kotlin.fir.types.ConeTypeProjection import org.jetbrains.kotlin.fir.types.ConeNullability class ConeClassLikeTypeImpl( override val lookupTag: ConeClassLikeLookupTag, - override val typeArguments: Array, + override val typeArguments: Array, isNullable: Boolean ) : ConeClassLikeType() { override val nullability: ConeNullability = ConeNullability.create(isNullable) diff --git a/compiler/fir/dump/src/org/jetbrains/kotlin/fir/dump/HtmlFirDump.kt b/compiler/fir/dump/src/org/jetbrains/kotlin/fir/dump/HtmlFirDump.kt index 6678c72e94b..c8cf9628093 100644 --- a/compiler/fir/dump/src/org/jetbrains/kotlin/fir/dump/HtmlFirDump.kt +++ b/compiler/fir/dump/src/org/jetbrains/kotlin/fir/dump/HtmlFirDump.kt @@ -22,7 +22,6 @@ import org.jetbrains.kotlin.fir.expressions.impl.FirUnitExpression import org.jetbrains.kotlin.fir.references.* import org.jetbrains.kotlin.fir.references.impl.FirSimpleNamedReference import org.jetbrains.kotlin.fir.resolve.directExpansionType -import org.jetbrains.kotlin.fir.resolve.firSymbolProvider import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol import org.jetbrains.kotlin.fir.resolve.diagnostics.FirAmbiguityError @@ -697,10 +696,10 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver generate(variableAssignment.rValue) } - private fun FlowContent.generate(projection: ConeKotlinTypeProjection) { + private fun FlowContent.generate(projection: ConeTypeProjection) { when (projection) { is ConeStarProjection -> +"*" - is ConeTypedProjection -> { + is ConeKotlinTypeProjection -> { when (projection.kind) { ProjectionKind.IN -> keyword("in ") ProjectionKind.OUT -> keyword("out ") diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt index 5a0f3f842e7..c80d825c6c5 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt @@ -110,7 +110,7 @@ private fun getArrayType(classId: ClassId?, irBuiltIns: IrBuiltIns): IrClassifie return irType?.let { irBuiltIns.primitiveArrayForType.getValue(it) } } -fun ConeKotlinTypeProjection.toIrTypeArgument( +fun ConeTypeProjection.toIrTypeArgument( session: FirSession, declarationStorage: Fir2IrDeclarationStorage, irBuiltIns: IrBuiltIns diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt index 67712a45e54..53db4636ce5 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt @@ -418,7 +418,7 @@ class Fir2IrVisitor( ).apply { val typeArguments = (constructedTypeRef as? FirResolvedTypeRef)?.type?.typeArguments if (typeArguments?.isNotEmpty() == true) { - val irType = (typeArguments.first() as ConeTypedProjection).type.toIrType(session, declarationStorage, irBuiltIns) + val irType = (typeArguments.first() as ConeKotlinTypeProjection).type.toIrType(session, declarationStorage, irBuiltIns) putTypeArgument(0, irType) } } diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/FirJavaElementFinder.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/FirJavaElementFinder.kt index 888d60dc24c..2b5ad0978f4 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/FirJavaElementFinder.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/FirJavaElementFinder.kt @@ -232,7 +232,7 @@ private fun ConeClassLikeType.mapToCanonicalNoExpansionString(session: FirSessio if (lookupTag.classId == StandardClassIds.Array) { return when (val typeProjection = typeArguments[0]) { is ConeStarProjection -> CommonClassNames.JAVA_LANG_OBJECT - is ConeTypedProjection -> { + is ConeKotlinTypeProjection -> { if (typeProjection.kind == ProjectionKind.IN) CommonClassNames.JAVA_LANG_VOID else @@ -259,10 +259,10 @@ private fun ConeClassLikeType.mapToCanonicalNoExpansionString(session: FirSessio } -private fun ConeKotlinTypeProjection.mapToCanonicalString(session: FirSession): String { +private fun ConeTypeProjection.mapToCanonicalString(session: FirSession): String { return when (this) { is ConeStarProjection -> "?" - is ConeTypedProjection -> { + is ConeKotlinTypeProjection -> { val wildcard = when (kind) { ProjectionKind.STAR -> error("Should be handled in the case above") ProjectionKind.IN -> "? super " diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaUtils.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaUtils.kt index 3d32cd0244b..064aa306457 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaUtils.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaUtils.kt @@ -63,7 +63,7 @@ internal val JavaClass.classKind: ClassKind } internal fun ClassId.toConeKotlinType( - typeArguments: Array, + typeArguments: Array, isNullable: Boolean ): ConeLookupTagBasedType { val lookupTag = ConeClassLikeLookupTagImpl(this) @@ -152,8 +152,8 @@ internal fun JavaType?.toConeKotlinTypeWithoutEnhancement( } private fun ClassId.toConeFlexibleType( - typeArguments: Array, - typeArgumentsForUpper: Array = typeArguments + typeArguments: Array, + typeArgumentsForUpper: Array = typeArguments ) = ConeFlexibleType( toConeKotlinType(typeArguments, isNullable = false), toConeKotlinType(typeArgumentsForUpper, isNullable = true) @@ -367,7 +367,7 @@ private fun JavaType?.toConeProjectionWithoutEnhancement( session: FirSession, javaTypeParameterStack: JavaTypeParameterStack, boundTypeParameter: FirTypeParameter? -): ConeKotlinTypeProjection { +): ConeTypeProjection { return when (this) { null -> ConeStarProjection is JavaWildcardType -> { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt index 638a0d3edaa..447088b2697 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirTypeDeserializer.kt @@ -155,7 +155,7 @@ class FirTypeDeserializer( } - private fun typeArgument(typeArgumentProto: ProtoBuf.Type.Argument): ConeKotlinTypeProjection { + private fun typeArgument(typeArgumentProto: ProtoBuf.Type.Argument): ConeTypeProjection { if (typeArgumentProto.projection == ProtoBuf.Type.Argument.Projection.STAR) { return ConeStarProjection } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt index 917562c8991..bc1302e4cb0 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt @@ -9,8 +9,6 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.declarations.* -import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind -import org.jetbrains.kotlin.fir.diagnostics.FirSimpleDiagnostic import org.jetbrains.kotlin.fir.diagnostics.FirStubDiagnostic import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression @@ -121,11 +119,11 @@ private fun mapTypeAliasArguments( return null } - override fun substituteArgument(projection: ConeKotlinTypeProjection): ConeKotlinTypeProjection? { - val type = (projection as? ConeTypedProjection)?.type ?: return null + override fun substituteArgument(projection: ConeTypeProjection): ConeTypeProjection? { + val type = (projection as? ConeKotlinTypeProjection)?.type ?: return null val symbol = (type as? ConeTypeParameterType)?.lookupTag?.toSymbol() ?: return super.substituteArgument(projection) val mappedProjection = typeAliasMap[symbol] ?: return super.substituteArgument(projection) - val mappedType = (mappedProjection as? ConeTypedProjection)?.type ?: return mappedProjection + val mappedType = (mappedProjection as? ConeKotlinTypeProjection)?.type ?: return mappedProjection val resultingKind = mappedProjection.kind + projection.kind return when (resultingKind) { ProjectionKind.STAR -> ConeStarProjection @@ -148,7 +146,7 @@ fun ConeClassifierLookupTag.toSymbol(useSiteSession: FirSession): FirClassifierS fun ConeTypeParameterLookupTag.toSymbol(): FirTypeParameterSymbol = this.symbol as FirTypeParameterSymbol -fun FirClassifierSymbol<*>.constructType(typeArguments: Array, isNullable: Boolean): ConeLookupTagBasedType { +fun FirClassifierSymbol<*>.constructType(typeArguments: Array, isNullable: Boolean): ConeLookupTagBasedType { return when (this) { is FirTypeParameterSymbol -> { ConeTypeParameterTypeImpl(this.toLookupTag(), isNullable) @@ -184,7 +182,7 @@ fun FirClassifierSymbol<*>.constructType( } -private fun List.toTypeProjections(): Array = flatMap { +private fun List.toTypeProjections(): Array = flatMap { it.typeArguments.map { typeArgument -> when (typeArgument) { is FirStarProjection -> ConeStarProjection diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SamResolution.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SamResolution.kt index 91d2c4c07f9..74bb8b1650c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SamResolution.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SamResolution.kt @@ -81,7 +81,7 @@ class FirSamResolverImpl( .map { it.symbol } .zip( type.typeArguments.map { - (it as? ConeTypedProjection)?.type + (it as? ConeKotlinTypeProjection)?.type ?: firSession.builtinTypes.nullableAnyType.type //ConeClassLikeTypeImpl(ConeClassLikeLookupTagImpl(StandardClassIds.Any), emptyArray(), isNullable = true) }, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt index 11b13cc4b18..c35af123fa8 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt @@ -57,13 +57,13 @@ fun FirClass<*>.buildUseSiteMemberScope(useSiteSession: FirSession, builder: Sco /* TODO REMOVE */ fun createSubstitution( typeParameters: List, - typeArguments: Array, + typeArguments: Array, session: FirSession ): Map { return typeParameters.zip(typeArguments) { typeParameter, typeArgument -> val typeParameterSymbol = typeParameter.symbol typeParameterSymbol to when (typeArgument) { - is ConeTypedProjection -> { + is ConeKotlinTypeProjection -> { typeArgument.type } else /* StarProjection */ -> { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt index d7f57710e4e..dc0221a80f7 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt @@ -103,7 +103,7 @@ internal sealed class CheckReceivers : ResolutionStage() { if (receiverType != null) return receiverType val returnTypeRef = callable.returnTypeRef as? FirResolvedTypeRef ?: return null if (!returnTypeRef.isExtensionFunctionType(bodyResolveComponents.session)) return null - return (returnTypeRef.type.typeArguments.firstOrNull() as? ConeTypedProjection)?.type + return (returnTypeRef.type.typeArguments.firstOrNull() as? ConeKotlinTypeProjection)?.type } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt index 998afd73a8f..5776ea882aa 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt @@ -80,7 +80,7 @@ fun ConeKotlinType.isSuspendFunctionType(session: FirSession): Boolean { fun ConeKotlinType.receiverType(expectedTypeRef: FirTypeRef, session: FirSession): ConeKotlinType? { if (isBuiltinFunctionalType(session) && expectedTypeRef.isExtensionFunctionType(session)) { - return ((this as ConeClassLikeType).fullyExpandedType(session).typeArguments.first() as ConeTypedProjection).type + return ((this as ConeClassLikeType).fullyExpandedType(session).typeArguments.first() as ConeKotlinTypeProjection).type } return null } @@ -88,13 +88,13 @@ fun ConeKotlinType.receiverType(expectedTypeRef: FirTypeRef, session: FirSession fun ConeKotlinType.returnType(session: FirSession): ConeKotlinType? { require(this is ConeClassLikeType) val projection = fullyExpandedType(session).typeArguments.last() - return (projection as? ConeTypedProjection)?.type + return (projection as? ConeKotlinTypeProjection)?.type } private fun ConeKotlinType.valueParameterTypesIncludingReceiver(session: FirSession): List { require(this is ConeClassLikeType) return fullyExpandedType(session).typeArguments.dropLast(1).map { - (it as? ConeTypedProjection)?.type + (it as? ConeKotlinTypeProjection)?.type } } @@ -119,7 +119,7 @@ private fun extraLambdaInfo( val receiverType = argument.receiverType val returnType = argument.returnType - ?: expectedType?.typeArguments?.singleOrNull()?.safeAs()?.type?.takeIf { isFunctionSupertype } + ?: expectedType?.typeArguments?.singleOrNull()?.safeAs()?.type?.takeIf { isFunctionSupertype } ?: typeVariable.defaultType val nothingType = argument.session.builtinTypes.nothingType.type diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt index 535c3ff37ca..ca01ed32d77 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt @@ -10,7 +10,7 @@ import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl abstract class AbstractConeSubstitutor : ConeSubstitutor() { - protected fun wrapProjection(old: ConeKotlinTypeProjection, newType: ConeKotlinType): ConeKotlinTypeProjection { + protected fun wrapProjection(old: ConeTypeProjection, newType: ConeKotlinType): ConeTypeProjection { return when (old) { is ConeStarProjection -> old is ConeKotlinTypeProjectionIn -> ConeKotlinTypeProjectionIn(newType) @@ -21,8 +21,8 @@ abstract class AbstractConeSubstitutor : ConeSubstitutor() { } abstract fun substituteType(type: ConeKotlinType): ConeKotlinType? - open fun substituteArgument(projection: ConeKotlinTypeProjection): ConeKotlinTypeProjection? { - val type = (projection as? ConeTypedProjection)?.type ?: return null + open fun substituteArgument(projection: ConeTypeProjection): ConeTypeProjection? { + val type = (projection as? ConeKotlinTypeProjection)?.type ?: return null val newType = substituteOrNull(type) ?: return null return wrapProjection(projection, newType) } @@ -88,7 +88,7 @@ abstract class AbstractConeSubstitutor : ConeSubstitutor() { } private fun ConeKotlinType.substituteArguments(): ConeKotlinType? { - val newArguments by lazy { arrayOfNulls(typeArguments.size) } + val newArguments by lazy { arrayOfNulls(typeArguments.size) } var initialized = false for ((index, typeArgument) in this.typeArguments.withIndex()) { newArguments[index] = substituteArgument(typeArgument)?.also { @@ -106,7 +106,7 @@ abstract class AbstractConeSubstitutor : ConeSubstitutor() { return when (this) { is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl( lookupTag, - newArguments as Array, + newArguments as Array, nullability.isNullable ) is ConeClassLikeType -> error("Unknown class-like type to substitute: $this, ${this::class}") diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt index 8ce75a54ce8..0476bb2ba15 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt @@ -550,7 +550,7 @@ class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransformer) : }.compose() } - private fun ConeKotlinTypeProjection.toFirTypeProjection(): FirTypeProjection = when (this) { + private fun ConeTypeProjection.toFirTypeProjection(): FirTypeProjection = when (this) { is ConeStarProjection -> buildStarProjection() else -> { val type = when (this) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ArrayUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ArrayUtils.kt index bb721a28504..a9925249452 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ArrayUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ArrayUtils.kt @@ -32,7 +32,7 @@ fun ConeKotlinType.arrayElementType(session: FirSession): ConeKotlinType? { if (type !is ConeClassLikeType) return null val classId = type.lookupTag.classId if (classId == StandardClassIds.Array) - return (type.typeArguments.first() as ConeTypedProjection).type + return (type.typeArguments.first() as ConeKotlinTypeProjection).type val elementType = StandardClassIds.elementTypeByPrimitiveArrayType[classId] if (elementType != null) { return elementType.invoke(session.firSymbolProvider).constructType(emptyArray(), isNullable = false) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt index a2ac67a1f4b..0112aefd01a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt @@ -58,7 +58,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo return when (constructor) { is FirClassLikeSymbol<*> -> ConeClassLikeTypeImpl( constructor.toLookupTag(), - (arguments as List).toTypedArray(), + (arguments as List).toTypedArray(), nullable ) is FirTypeParameterSymbol -> ConeTypeParameterTypeImpl( @@ -107,7 +107,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo var maxArgumentDepth = 0 for (arg in typeArguments) { - val current = if (arg is ConeStarProjection) 1 else (arg as ConeTypedProjection).type.typeDepth() + val current = if (arg is ConeStarProjection) 1 else (arg as ConeKotlinTypeProjection).type.typeDepth() if (current > maxArgumentDepth) { maxArgumentDepth = current } @@ -217,7 +217,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo captureStatus: CaptureStatus ): CapturedTypeMarker { require(lowerType is ConeKotlinType?) - require(constructorProjection is ConeKotlinTypeProjection) + require(constructorProjection is ConeTypeProjection) return ConeCapturedType( captureStatus, lowerType, @@ -236,7 +236,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo override fun SimpleTypeMarker.replaceArguments(newArguments: List): SimpleTypeMarker { require(this is ConeKotlinType) - return this.withArguments(newArguments.cast>().toTypedArray()) + return this.withArguments(newArguments.cast>().toTypedArray()) } override fun KotlinTypeMarker.hasExactAnnotation(): Boolean { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt index f1a75c016f9..81303465cf1 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt @@ -175,12 +175,12 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty } override fun TypeArgumentMarker.isStarProjection(): Boolean { - require(this is ConeKotlinTypeProjection) + require(this is ConeTypeProjection) return this is ConeStarProjection } override fun TypeArgumentMarker.getVariance(): TypeVariance { - require(this is ConeKotlinTypeProjection) + require(this is ConeTypeProjection) return when (this.kind) { ProjectionKind.STAR -> error("Nekorrektno (c) Stas") @@ -191,8 +191,8 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty } override fun TypeArgumentMarker.getType(): KotlinTypeMarker { - require(this is ConeKotlinTypeProjection) - require(this is ConeTypedProjection) { "No type for StarProjection" } + require(this is ConeTypeProjection) + require(this is ConeKotlinTypeProjection) { "No type for StarProjection" } return this.type } @@ -310,7 +310,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty if (argument !is ConeStarProjection && argument.kind == ProjectionKind.INVARIANT) return@Array argument val lowerType = if (argument !is ConeStarProjection && argument.getVariance() == TypeVariance.IN) { - (argument as ConeTypedProjection).type + (argument as ConeKotlinTypeProjection).type } else { null } @@ -516,7 +516,7 @@ class ConeTypeCheckerContext( val substitutor = if (declaration is FirTypeParametersOwner) { val substitution = declaration.typeParameters.zip(type.typeArguments).associate { (parameter, argument) -> - parameter.symbol to ((argument as? ConeTypedProjection)?.type + parameter.symbol to ((argument as? ConeKotlinTypeProjection)?.type ?: session.builtinTypes.nullableAnyType.type)//StandardClassIds.Any(session.firSymbolProvider).constructType(emptyArray(), isNullable = true)) } substitutorByMap(substitution) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt index 7ced10bbfd7..30a129e1421 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt @@ -85,7 +85,7 @@ fun ConeKotlinType.makeConeTypeDefinitelyNotNullOrNotNull(): ConeKotlinType { return ConeDefinitelyNotNullType.create(this) ?: this.withNullability(ConeNullability.NOT_NULL) } -fun T.withArguments(arguments: Array): T { +fun T.withArguments(arguments: Array): T { if (this.typeArguments === arguments) { return this } @@ -175,7 +175,7 @@ fun coneFlexibleOrSimpleType( } } -fun ConeKotlinType.toTypeProjection(variance: Variance): ConeKotlinTypeProjection = +fun ConeKotlinType.toTypeProjection(variance: Variance): ConeTypeProjection = when (variance) { Variance.INVARIANT -> this Variance.IN_VARIANCE -> ConeKotlinTypeProjectionIn(this) @@ -183,13 +183,13 @@ fun ConeKotlinType.toTypeProjection(variance: Variance): ConeKotlinTypeProjectio } fun ConeClassLikeLookupTag.constructClassType( - typeArguments: Array, + typeArguments: Array, isNullable: Boolean, ): ConeClassLikeType { return ConeClassLikeTypeImpl(this, typeArguments, isNullable) } -fun ConeClassifierLookupTag.constructType(typeArguments: Array, isNullable: Boolean): ConeLookupTagBasedType { +fun ConeClassifierLookupTag.constructType(typeArguments: Array, isNullable: Boolean): ConeLookupTagBasedType { return when (this) { is ConeTypeParameterLookupTag -> ConeTypeParameterTypeImpl(this, isNullable) is ConeClassLikeLookupTag -> this.constructClassType(typeArguments, isNullable) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/ConeTypeParameterTypeImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/ConeTypeParameterTypeImpl.kt index 9f310b9be28..3dfabd49e0b 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/ConeTypeParameterTypeImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/ConeTypeParameterTypeImpl.kt @@ -6,7 +6,7 @@ package org.jetbrains.kotlin.fir.types.impl import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag -import org.jetbrains.kotlin.fir.types.ConeKotlinTypeProjection +import org.jetbrains.kotlin.fir.types.ConeTypeProjection import org.jetbrains.kotlin.fir.types.ConeNullability import org.jetbrains.kotlin.fir.types.ConeTypeParameterType @@ -14,7 +14,7 @@ class ConeTypeParameterTypeImpl( override val lookupTag: ConeTypeParameterLookupTag, isNullable: Boolean ) : ConeTypeParameterType() { - override val typeArguments: Array + override val typeArguments: Array get() = EMPTY_ARRAY override val nullability: ConeNullability = ConeNullability.create(isNullable) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirImplicitBuiltinTypeRef.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirImplicitBuiltinTypeRef.kt index 6d17f30837d..40e32330e3c 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirImplicitBuiltinTypeRef.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirImplicitBuiltinTypeRef.kt @@ -11,7 +11,7 @@ import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.symbols.StandardClassIds import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl import org.jetbrains.kotlin.fir.types.ConeClassLikeType -import org.jetbrains.kotlin.fir.types.ConeKotlinTypeProjection +import org.jetbrains.kotlin.fir.types.ConeTypeProjection import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.visitors.FirTransformer @@ -21,7 +21,7 @@ import org.jetbrains.kotlin.name.ClassId sealed class FirImplicitBuiltinTypeRef( override val source: FirSourceElement?, val id: ClassId, - typeArguments: Array = emptyArray(), + typeArguments: Array = emptyArray(), isNullable: Boolean = false ) : FirResolvedTypeRef() { override val annotations: List @@ -77,5 +77,5 @@ class FirImplicitStringTypeRef( class FirImplicitKPropertyTypeRef( source: FirSourceElement?, - typeArgument: ConeKotlinTypeProjection + typeArgument: ConeTypeProjection ) : FirImplicitBuiltinTypeRef(source, StandardClassIds.KProperty, arrayOf(typeArgument))