[FIR] Reorganize ConeKotlinTypeProjection hierarchy

This commit is contained in:
simon.ogorodnik
2020-02-26 16:38:15 +03:00
parent 7c4f59dfcb
commit f405b3f827
22 changed files with 72 additions and 78 deletions
@@ -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<ConeKotlinTypeProjection>()
val EMPTY_ARRAY = arrayOf<ConeTypeProjection>()
}
}
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<out ConeKotlinTypeProjection>
abstract val typeArguments: Array<out ConeTypeProjection>
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("<error>"))
override val typeArguments: Array<out ConeKotlinTypeProjection>
override val typeArguments: Array<out ConeTypeProjection>
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<out ConeKotlinTypeProjection>
override val typeArguments: Array<out ConeTypeProjection>
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<ConeKotlinType>? = 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<out ConeKotlinTypeProjection>
override val typeArguments: Array<out ConeTypeProjection>
get() = emptyArray()
}
@@ -170,11 +167,11 @@ data class ConeTypeVariableType(
override val nullability: ConeNullability,
override val lookupTag: ConeClassifierLookupTag
) : ConeLookupTagBasedType() {
override val typeArguments: Array<out ConeKotlinTypeProjection> get() = emptyArray()
override val typeArguments: Array<out ConeTypeProjection> get() = emptyArray()
}
data class ConeDefinitelyNotNullType(val original: ConeKotlinType) : ConeSimpleKotlinType(), DefinitelyNotNullTypeMarker {
override val typeArguments: Array<out ConeKotlinTypeProjection>
override val typeArguments: Array<out ConeTypeProjection>
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<ConeKotlinType>
) : ConeSimpleKotlinType(), TypeConstructorMarker {
override val typeArguments: Array<out ConeKotlinTypeProjection>
override val typeArguments: Array<out ConeTypeProjection>
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<out ConeKotlinTypeProjection>
override val typeArguments: Array<out ConeTypeProjection>
get() = emptyArray()
}
@@ -226,7 +223,7 @@ abstract class ConeIntegerLiteralType(val value: Long) : ConeSimpleKotlinType(),
abstract val possibleTypes: Collection<ConeClassLikeType>
abstract val supertypes: List<ConeClassLikeType>
override val typeArguments: Array<out ConeKotlinTypeProjection> = emptyArray()
override val typeArguments: Array<out ConeTypeProjection> = emptyArray()
override val nullability: ConeNullability = ConeNullability.NOT_NULL
abstract fun getApproximatedType(expectedType: ConeKotlinType? = null): ConeClassLikeType
@@ -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()}"
@@ -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<out ConeKotlinTypeProjection>,
override val typeArguments: Array<out ConeTypeProjection>,
isNullable: Boolean
) : ConeClassLikeType() {
override val nullability: ConeNullability = ConeNullability.create(isNullable)
@@ -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 ")
@@ -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
@@ -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)
}
}
@@ -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 "
@@ -63,7 +63,7 @@ internal val JavaClass.classKind: ClassKind
}
internal fun ClassId.toConeKotlinType(
typeArguments: Array<ConeKotlinTypeProjection>,
typeArguments: Array<ConeTypeProjection>,
isNullable: Boolean
): ConeLookupTagBasedType {
val lookupTag = ConeClassLikeLookupTagImpl(this)
@@ -152,8 +152,8 @@ internal fun JavaType?.toConeKotlinTypeWithoutEnhancement(
}
private fun ClassId.toConeFlexibleType(
typeArguments: Array<ConeKotlinTypeProjection>,
typeArgumentsForUpper: Array<ConeKotlinTypeProjection> = typeArguments
typeArguments: Array<ConeTypeProjection>,
typeArgumentsForUpper: Array<ConeTypeProjection> = 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 -> {
@@ -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
}
@@ -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<ConeKotlinTypeProjection>, isNullable: Boolean): ConeLookupTagBasedType {
fun FirClassifierSymbol<*>.constructType(typeArguments: Array<ConeTypeProjection>, isNullable: Boolean): ConeLookupTagBasedType {
return when (this) {
is FirTypeParameterSymbol -> {
ConeTypeParameterTypeImpl(this.toLookupTag(), isNullable)
@@ -184,7 +182,7 @@ fun FirClassifierSymbol<*>.constructType(
}
private fun List<FirQualifierPart>.toTypeProjections(): Array<ConeKotlinTypeProjection> = flatMap {
private fun List<FirQualifierPart>.toTypeProjections(): Array<ConeTypeProjection> = flatMap {
it.typeArguments.map { typeArgument ->
when (typeArgument) {
is FirStarProjection -> ConeStarProjection
@@ -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)
},
@@ -57,13 +57,13 @@ fun FirClass<*>.buildUseSiteMemberScope(useSiteSession: FirSession, builder: Sco
/* TODO REMOVE */
fun createSubstitution(
typeParameters: List<FirTypeParameter>,
typeArguments: Array<out ConeKotlinTypeProjection>,
typeArguments: Array<out ConeTypeProjection>,
session: FirSession
): Map<FirTypeParameterSymbol, ConeKotlinType> {
return typeParameters.zip(typeArguments) { typeParameter, typeArgument ->
val typeParameterSymbol = typeParameter.symbol
typeParameterSymbol to when (typeArgument) {
is ConeTypedProjection -> {
is ConeKotlinTypeProjection -> {
typeArgument.type
}
else /* StarProjection */ -> {
@@ -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
}
}
@@ -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<ConeKotlinType?> {
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<ConeTypedProjection>()?.type?.takeIf { isFunctionSupertype }
?: expectedType?.typeArguments?.singleOrNull()?.safeAs<ConeKotlinTypeProjection>()?.type?.takeIf { isFunctionSupertype }
?: typeVariable.defaultType
val nothingType = argument.session.builtinTypes.nothingType.type
@@ -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<ConeKotlinTypeProjection>(typeArguments.size) }
val newArguments by lazy { arrayOfNulls<ConeTypeProjection>(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<ConeKotlinTypeProjection>,
newArguments as Array<ConeTypeProjection>,
nullability.isNullable
)
is ConeClassLikeType -> error("Unknown class-like type to substitute: $this, ${this::class}")
@@ -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) {
@@ -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)
@@ -58,7 +58,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
return when (constructor) {
is FirClassLikeSymbol<*> -> ConeClassLikeTypeImpl(
constructor.toLookupTag(),
(arguments as List<ConeKotlinTypeProjection>).toTypedArray(),
(arguments as List<ConeTypeProjection>).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<TypeArgumentMarker>): SimpleTypeMarker {
require(this is ConeKotlinType)
return this.withArguments(newArguments.cast<List<ConeKotlinTypeProjection>>().toTypedArray())
return this.withArguments(newArguments.cast<List<ConeTypeProjection>>().toTypedArray())
}
override fun KotlinTypeMarker.hasExactAnnotation(): Boolean {
@@ -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)
@@ -85,7 +85,7 @@ fun ConeKotlinType.makeConeTypeDefinitelyNotNullOrNotNull(): ConeKotlinType {
return ConeDefinitelyNotNullType.create(this) ?: this.withNullability(ConeNullability.NOT_NULL)
}
fun <T : ConeKotlinType> T.withArguments(arguments: Array<out ConeKotlinTypeProjection>): T {
fun <T : ConeKotlinType> T.withArguments(arguments: Array<out ConeTypeProjection>): 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<out ConeKotlinTypeProjection>,
typeArguments: Array<out ConeTypeProjection>,
isNullable: Boolean,
): ConeClassLikeType {
return ConeClassLikeTypeImpl(this, typeArguments, isNullable)
}
fun ConeClassifierLookupTag.constructType(typeArguments: Array<out ConeKotlinTypeProjection>, isNullable: Boolean): ConeLookupTagBasedType {
fun ConeClassifierLookupTag.constructType(typeArguments: Array<out ConeTypeProjection>, isNullable: Boolean): ConeLookupTagBasedType {
return when (this) {
is ConeTypeParameterLookupTag -> ConeTypeParameterTypeImpl(this, isNullable)
is ConeClassLikeLookupTag -> this.constructClassType(typeArguments, isNullable)
@@ -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<out ConeKotlinTypeProjection>
override val typeArguments: Array<out ConeTypeProjection>
get() = EMPTY_ARRAY
override val nullability: ConeNullability = ConeNullability.create(isNullable)
@@ -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<out ConeKotlinTypeProjection> = emptyArray(),
typeArguments: Array<out ConeTypeProjection> = emptyArray(),
isNullable: Boolean = false
) : FirResolvedTypeRef() {
override val annotations: List<FirAnnotationCall>
@@ -77,5 +77,5 @@ class FirImplicitStringTypeRef(
class FirImplicitKPropertyTypeRef(
source: FirSourceElement?,
typeArgument: ConeKotlinTypeProjection
typeArgument: ConeTypeProjection
) : FirImplicitBuiltinTypeRef(source, StandardClassIds.KProperty, arrayOf(typeArgument))