FIR: Support special scope for raw types

^KT-46369 Fixed
^KT-41794 Fixed
^KT-49351 Fixed
This commit is contained in:
Denis.Zharkov
2022-10-13 10:50:45 +02:00
committed by Space Team
parent 1215ae0fe7
commit 5cc31114cd
39 changed files with 225 additions and 255 deletions
@@ -68,6 +68,16 @@ object CompilerConeAttributes {
override fun toString(): String = "@ExtensionFunctionType"
}
object RawType : ConeAttribute<RawType>() {
override fun union(other: RawType?): RawType? = other
override fun intersect(other: RawType?): RawType? = other
override fun add(other: RawType?): RawType = this
override fun isSubtypeOf(other: RawType?): Boolean = true
override val key: KClass<out RawType> = RawType::class
override fun toString(): String = "Raw type"
}
class ContextFunctionTypeParams(val contextReceiverNumber: Int) : ConeAttribute<ContextFunctionTypeParams>() {
override fun union(other: ContextFunctionTypeParams?): ContextFunctionTypeParams? = other
override fun intersect(other: ContextFunctionTypeParams?): ContextFunctionTypeParams = this
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.types
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.types.model.*
import org.jetbrains.kotlin.utils.addToStdlib.foldMap
@@ -184,10 +185,32 @@ data class ConeDefinitelyNotNullType(val original: ConeSimpleKotlinType) : ConeS
companion object
}
class ConeRawType(
class ConeRawType private constructor(
lowerBound: ConeSimpleKotlinType,
upperBound: ConeSimpleKotlinType
) : ConeFlexibleType(lowerBound, upperBound), RawTypeMarker
) : ConeFlexibleType(lowerBound, upperBound), RawTypeMarker {
companion object {
fun create(
lowerBound: ConeSimpleKotlinType,
upperBound: ConeSimpleKotlinType,
): ConeRawType {
require(lowerBound is ConeClassLikeType && upperBound is ConeClassLikeType) {
"Raw bounds are expected to be class-like types, but $lowerBound and $upperBound were found"
}
val lowerBoundToUse = if (!lowerBound.attributes.contains(CompilerConeAttributes.RawType)) {
ConeClassLikeTypeImpl(
lowerBound.lookupTag, lowerBound.typeArguments, lowerBound.isNullable,
lowerBound.attributes + CompilerConeAttributes.RawType
)
} else {
lowerBound
}
return ConeRawType(lowerBoundToUse, upperBound)
}
}
}
/*
* Contract of the intersection type: it is flat. It means that