mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-01 15:51:52 +00:00
[FIR] Update type parameter use-sites to use type parameter refs
This commit is contained in:
@@ -925,24 +925,36 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver
|
||||
}
|
||||
}
|
||||
|
||||
private fun FlowContent.generateTypeParameters(typeParameterContainer: FirTypeParametersOwner) {
|
||||
private fun FlowContent.generateTypeParameters(typeParameterContainer: FirTypeParameterRefsOwner, describe: Boolean = false) {
|
||||
if (typeParameterContainer.typeParameters.isEmpty()) return
|
||||
+"<"
|
||||
generateList(typeParameterContainer.typeParameters) {
|
||||
generate(it.variance)
|
||||
if (it.isReified) {
|
||||
fun generateTypeParameter(typeParameter: FirTypeParameter, describe: Boolean) {
|
||||
generate(typeParameter.variance)
|
||||
if (typeParameter.isReified) {
|
||||
keyword("reified ")
|
||||
}
|
||||
symbolAnchor(it.symbol) {
|
||||
simpleName(it.name)
|
||||
}
|
||||
if (it.bounds.isNotEmpty()) {
|
||||
if (describe)
|
||||
simpleName(typeParameter.name)
|
||||
else
|
||||
symbolAnchor(typeParameter.symbol) {
|
||||
simpleName(typeParameter.name)
|
||||
}
|
||||
if (typeParameter.bounds.isNotEmpty()) {
|
||||
+": "
|
||||
generateList(it.bounds) { bound ->
|
||||
generateList(typeParameter.bounds) { bound ->
|
||||
generate(bound)
|
||||
}
|
||||
}
|
||||
}
|
||||
generateList(typeParameterContainer.typeParameters) {
|
||||
if (it is FirTypeParameter) {
|
||||
generateTypeParameter(it, describe)
|
||||
} else {
|
||||
symbolRef(it.symbol) {
|
||||
generateTypeParameter(it.symbol.fir, describe = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
+"> "
|
||||
}
|
||||
|
||||
@@ -1129,26 +1141,8 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver
|
||||
generate(fir.returnTypeRef)
|
||||
}
|
||||
|
||||
private fun FlowContent.describeTypeParameters(typeParameterContainer: FirTypeParametersOwner) {
|
||||
if (typeParameterContainer.typeParameters.isEmpty()) return
|
||||
+"<"
|
||||
generateList(typeParameterContainer.typeParameters) {
|
||||
generate(it.variance)
|
||||
if (it.isReified) {
|
||||
keyword("reified ")
|
||||
}
|
||||
|
||||
simpleName(it.name)
|
||||
|
||||
if (it.bounds.isNotEmpty()) {
|
||||
+": "
|
||||
generateList(it.bounds) { bound ->
|
||||
generate(bound)
|
||||
}
|
||||
}
|
||||
}
|
||||
+"> "
|
||||
}
|
||||
private fun FlowContent.describeTypeParameters(typeParameterContainer: FirTypeParameterRefsOwner) =
|
||||
generateTypeParameters(typeParameterContainer, describe = true)
|
||||
|
||||
private fun FlowContent.describeVerbose(symbol: FirBasedSymbol<*>) {
|
||||
when (symbol) {
|
||||
|
||||
@@ -78,23 +78,25 @@ class Fir2IrClassifierStorage(
|
||||
symbolTable.leaveScope(descriptor)
|
||||
}
|
||||
|
||||
internal fun preCacheTypeParameters(owner: FirTypeParametersOwner) {
|
||||
owner.typeParameters.mapIndexed { index, typeParameter ->
|
||||
getCachedIrTypeParameter(typeParameter, index)
|
||||
?: createIrTypeParameterWithoutBounds(typeParameter, index)
|
||||
internal fun preCacheTypeParameters(owner: FirTypeParameterRefsOwner) {
|
||||
for ((index, typeParameter) in owner.typeParameters.withIndex()) {
|
||||
val original = typeParameter.symbol.fir
|
||||
getCachedIrTypeParameter(original, index)
|
||||
?: createIrTypeParameterWithoutBounds(original, index)
|
||||
if (owner is FirProperty && owner.isVar) {
|
||||
val context = ConversionTypeContext.DEFAULT.inSetter()
|
||||
getCachedIrTypeParameter(typeParameter, index, context)
|
||||
?: createIrTypeParameterWithoutBounds(typeParameter, index, context)
|
||||
getCachedIrTypeParameter(original, index, context)
|
||||
?: createIrTypeParameterWithoutBounds(original, index, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun IrTypeParametersContainer.setTypeParameters(
|
||||
owner: FirTypeParametersOwner,
|
||||
owner: FirTypeParameterRefsOwner,
|
||||
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT
|
||||
) {
|
||||
typeParameters = owner.typeParameters.mapIndexed { index, typeParameter ->
|
||||
typeParameters = owner.typeParameters.mapIndexedNotNull { index, typeParameter ->
|
||||
if (typeParameter !is FirTypeParameter) return@mapIndexedNotNull null
|
||||
getIrTypeParameter(typeParameter, index, typeContext).apply {
|
||||
parent = this@setTypeParameters
|
||||
if (superTypes.isEmpty()) {
|
||||
|
||||
@@ -88,7 +88,7 @@ class FirJavaElementFinder(
|
||||
|
||||
newTypeParameterList(
|
||||
stub,
|
||||
firClass.typeParameters.map { Pair(it.name.asString(), arrayOf(CommonClassNames.JAVA_LANG_OBJECT)) }
|
||||
firClass.typeParameters.filterIsInstance<FirTypeParameter>().map { Pair(it.name.asString(), arrayOf(CommonClassNames.JAVA_LANG_OBJECT)) }
|
||||
)
|
||||
|
||||
val superTypeRefs = when {
|
||||
|
||||
@@ -318,7 +318,7 @@ private fun JavaClassifierType.toConeKotlinTypeForFlexibleBound(
|
||||
private fun FirRegularClass.createRawArguments(
|
||||
defaultArgs: List<ConeStarProjection>,
|
||||
position: TypeComponentPosition
|
||||
) = typeParameters.map { typeParameter ->
|
||||
) = typeParameters.filterIsInstance<FirTypeParameter>().map { typeParameter ->
|
||||
val erasedUpperBound = typeParameter.getErasedUpperBound {
|
||||
defaultType().withArguments(defaultArgs.toTypedArray())
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class FirJavaClass @FirImplementationDetail internal constructor(
|
||||
override val scopeProvider: FirScopeProvider,
|
||||
override val symbol: FirRegularClassSymbol,
|
||||
override val superTypeRefs: MutableList<FirTypeRef>,
|
||||
override val typeParameters: MutableList<FirTypeParameter>,
|
||||
override val typeParameters: MutableList<FirTypeParameterRef>,
|
||||
internal val javaTypeParameterStack: JavaTypeParameterStack,
|
||||
internal val existingNestedClassifierNames: List<Name>
|
||||
) : FirRegularClass() {
|
||||
@@ -114,7 +114,7 @@ internal class FirJavaClassBuilder : AbstractFirRegularClassBuilder, FirAnnotati
|
||||
override var resolvePhase: FirResolvePhase = FirResolvePhase.RAW_FIR
|
||||
override lateinit var name: Name
|
||||
override val annotations: MutableList<FirAnnotationCall> = mutableListOf()
|
||||
override val typeParameters: MutableList<FirTypeParameter> = mutableListOf()
|
||||
override val typeParameters: MutableList<FirTypeParameterRef> = mutableListOf()
|
||||
override lateinit var status: FirDeclarationStatus
|
||||
override lateinit var classKind: ClassKind
|
||||
override val declarations: MutableList<FirDeclaration> = mutableListOf()
|
||||
|
||||
@@ -34,7 +34,7 @@ class FirJavaConstructor @FirImplementationDetail constructor(
|
||||
override val isPrimary: Boolean,
|
||||
override var returnTypeRef: FirTypeRef,
|
||||
override val valueParameters: MutableList<FirValueParameter>,
|
||||
override val typeParameters: MutableList<FirTypeParameter>,
|
||||
override val typeParameters: MutableList<FirTypeParameterRef>,
|
||||
override val annotations: MutableList<FirAnnotationCall>,
|
||||
override var status: FirDeclarationStatus,
|
||||
override var resolvePhase: FirResolvePhase,
|
||||
|
||||
@@ -59,7 +59,6 @@ class FirJavaMethod @FirImplementationDetail constructor(
|
||||
resolvePhase,
|
||||
returnTypeRef,
|
||||
receiverTypeRef,
|
||||
typeParameters,
|
||||
valueParameters,
|
||||
body,
|
||||
status,
|
||||
@@ -67,6 +66,7 @@ class FirJavaMethod @FirImplementationDetail constructor(
|
||||
name,
|
||||
symbol,
|
||||
annotations,
|
||||
typeParameters,
|
||||
)
|
||||
|
||||
private val ALL_JAVA_OPERATION_NAMES =
|
||||
|
||||
@@ -366,6 +366,12 @@ class RawFirBuilder(
|
||||
extractAnnotationsTo(container.annotations)
|
||||
}
|
||||
|
||||
private fun KtTypeParameterListOwner.extractTypeParametersTo(container: FirTypeParameterRefsOwnerBuilder) {
|
||||
for (typeParameter in typeParameters) {
|
||||
container.typeParameters += typeParameter.convert<FirTypeParameter>()
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtTypeParameterListOwner.extractTypeParametersTo(container: FirTypeParametersOwnerBuilder) {
|
||||
for (typeParameter in typeParameters) {
|
||||
container.typeParameters += typeParameter.convert<FirTypeParameter>()
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRefsOwner
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParametersOwner
|
||||
import org.jetbrains.kotlin.fir.declarations.addDefaultBoundIfNecessary
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.FirTypeParameterBuilder
|
||||
@@ -118,7 +119,7 @@ class FirTypeDeserializer(
|
||||
|
||||
|
||||
fun FirClassLikeSymbol<*>.typeParameters(): List<FirTypeParameterSymbol> =
|
||||
(fir as? FirTypeParametersOwner)?.typeParameters?.map { it.symbol }.orEmpty()
|
||||
(fir as? FirTypeParameterRefsOwner)?.typeParameters?.map { it.symbol }.orEmpty()
|
||||
|
||||
fun simpleType(proto: ProtoBuf.Type): ConeLookupTagBasedType? {
|
||||
|
||||
@@ -179,7 +180,7 @@ class FirTypeDeserializer(
|
||||
isNullable: Boolean
|
||||
): ConeClassLikeType {
|
||||
val result =
|
||||
when (functionTypeConstructor.toSymbol(session)!!.firUnsafe<FirTypeParametersOwner>().typeParameters.size - arguments.size) {
|
||||
when (functionTypeConstructor.toSymbol(session)!!.firUnsafe<FirTypeParameterRefsOwner>().typeParameters.size - arguments.size) {
|
||||
0 -> createSuspendFunctionTypeForBasicCase(/* annotations, */ functionTypeConstructor, arguments, isNullable)
|
||||
// This case for types written by eap compiler 1.1
|
||||
1 -> {
|
||||
|
||||
@@ -120,14 +120,15 @@ class FirSamResolverImpl(
|
||||
)
|
||||
|
||||
val newTypeParameters = firRegularClass.typeParameters.map { typeParameter ->
|
||||
val declaredTypeParameter = typeParameter.symbol.fir // TODO: or really declared?
|
||||
FirTypeParameterBuilder().apply {
|
||||
source = typeParameter.source
|
||||
source = declaredTypeParameter.source
|
||||
session = firSession
|
||||
name = typeParameter.name
|
||||
name = declaredTypeParameter.name
|
||||
this.symbol = FirTypeParameterSymbol()
|
||||
variance = Variance.INVARIANT
|
||||
isReified = false
|
||||
annotations += typeParameter.annotations
|
||||
annotations += declaredTypeParameter.annotations
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +143,8 @@ class FirSamResolverImpl(
|
||||
)
|
||||
|
||||
for ((newTypeParameter, oldTypeParameter) in newTypeParameters.zip(firRegularClass.typeParameters)) {
|
||||
newTypeParameter.bounds += oldTypeParameter.bounds.mapNotNull { typeRef ->
|
||||
val declared = oldTypeParameter.symbol.fir // TODO: or really declared?
|
||||
newTypeParameter.bounds += declared.bounds.mapNotNull { typeRef ->
|
||||
buildResolvedTypeRef {
|
||||
source = typeRef.source
|
||||
type = substitutor.substituteOrSelf(typeRef.coneTypeSafe() ?: return@mapNotNull null)
|
||||
|
||||
@@ -6,10 +6,7 @@
|
||||
package org.jetbrains.kotlin.fir.resolve
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParametersOwner
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirCompositeScope
|
||||
@@ -28,10 +25,7 @@ fun ConeKotlinType.scope(useSiteSession: FirSession, scopeSession: ScopeSession)
|
||||
val fullyExpandedType = fullyExpandedType(useSiteSession)
|
||||
val fir = fullyExpandedType.lookupTag.toSymbol(useSiteSession)?.fir as? FirClass<*> ?: return null
|
||||
|
||||
val substitution = when (fir) {
|
||||
is FirTypeParametersOwner -> createSubstitution(fir.typeParameters, fullyExpandedType.typeArguments, useSiteSession)
|
||||
else -> emptyMap()
|
||||
}
|
||||
val substitution = createSubstitution(fir.typeParameters, fullyExpandedType.typeArguments, useSiteSession)
|
||||
|
||||
fir.scope(substitutorByMap(substitution), useSiteSession, scopeSession, skipPrivateMembers = false)
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ fun FirClass<*>.buildUseSiteMemberScope(useSiteSession: FirSession, builder: Sco
|
||||
|
||||
/* TODO REMOVE */
|
||||
fun createSubstitution(
|
||||
typeParameters: List<FirTypeParameter>,
|
||||
typeParameters: List<FirTypeParameterRef>, // TODO: or really declared?
|
||||
typeArguments: Array<out ConeTypeProjection>,
|
||||
session: FirSession
|
||||
): Map<FirTypeParameterSymbol, ConeKotlinType> {
|
||||
@@ -86,7 +86,7 @@ fun ConeClassLikeType.wrapSubstitutionScopeIfNeed(
|
||||
): FirScope {
|
||||
if (this.typeArguments.isEmpty()) return useSiteMemberScope
|
||||
return builder.getOrBuild(declaration.symbol, SubstitutionScopeKey(this)) {
|
||||
val typeParameters = (declaration as? FirTypeParametersOwner)?.typeParameters.orEmpty()
|
||||
val typeParameters = (declaration as? FirTypeParameterRefsOwner)?.typeParameters.orEmpty()
|
||||
val originalSubstitution = createSubstitution(typeParameters, typeArguments, session)
|
||||
val javaClassId = JavaToKotlinClassMap.mapKotlinToJava(declaration.symbol.classId.asSingleFqName().toUnsafe())
|
||||
val javaClass = javaClassId?.let { session.firSymbolProvider.getClassLikeSymbolByFqName(it)?.fir } as? FirRegularClass
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRefsOwner
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRef
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParametersOwner
|
||||
import org.jetbrains.kotlin.fir.renderWithType
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.TypeParameterBasedTypeVariable
|
||||
@@ -22,7 +24,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystem
|
||||
internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() {
|
||||
override suspend fun check(candidate: Candidate, sink: CheckerSink, callInfo: CallInfo) {
|
||||
val declaration = candidate.symbol.fir
|
||||
if (declaration !is FirTypeParametersOwner || declaration.typeParameters.isEmpty()) {
|
||||
if (declaration !is FirTypeParameterRefsOwner || declaration.typeParameters.isEmpty()) {
|
||||
candidate.substitutor = ConeSubstitutor.Empty
|
||||
candidate.freshVariables = emptyList()
|
||||
return
|
||||
@@ -73,7 +75,7 @@ internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() {
|
||||
)
|
||||
is FirStarProjection -> csBuilder.addEqualityConstraint(
|
||||
freshVariable.defaultType,
|
||||
typeParameter.bounds.firstOrNull()?.coneTypeUnsafe()
|
||||
typeParameter.symbol.fir.bounds.firstOrNull()?.coneTypeUnsafe()
|
||||
?: sink.components.session.builtinTypes.nullableAnyType.type,
|
||||
SimpleConstraintSystemConstraintPosition
|
||||
)
|
||||
@@ -86,7 +88,7 @@ internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() {
|
||||
|
||||
private fun getTypePreservingFlexibilityWrtTypeVariable(
|
||||
type: ConeKotlinType,
|
||||
typeParameter: FirTypeParameter,
|
||||
typeParameter: FirTypeParameterRef,
|
||||
context: ConeTypeContext
|
||||
): ConeKotlinType {
|
||||
return if (typeParameter.shouldBeFlexible(context)) {
|
||||
@@ -97,8 +99,8 @@ internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun FirTypeParameter.shouldBeFlexible(context: ConeTypeContext): Boolean {
|
||||
return bounds.any {
|
||||
private fun FirTypeParameterRef.shouldBeFlexible(context: ConeTypeContext): Boolean {
|
||||
return symbol.fir.bounds.any {
|
||||
val type = it.coneTypeUnsafe<ConeKotlinType>()
|
||||
type is ConeFlexibleType || with(context) {
|
||||
(type.typeConstructor() as? FirTypeParameterSymbol)?.fir?.shouldBeFlexible(context) ?: false
|
||||
@@ -109,7 +111,7 @@ internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() {
|
||||
}
|
||||
|
||||
fun createToFreshVariableSubstitutorAndAddInitialConstraints(
|
||||
declaration: FirTypeParametersOwner,
|
||||
declaration: FirTypeParameterRefsOwner,
|
||||
candidate: Candidate,
|
||||
csBuilder: ConstraintSystemOperation
|
||||
): Pair<ConeSubstitutor, List<ConeTypeVariable>> {
|
||||
@@ -136,7 +138,7 @@ fun createToFreshVariableSubstitutorAndAddInitialConstraints(
|
||||
val freshVariable = freshTypeVariables[index]
|
||||
//val position = DeclaredUpperBoundConstraintPosition(typeParameter)
|
||||
|
||||
for (upperBound in typeParameter.bounds) {
|
||||
for (upperBound in typeParameter.symbol.fir.bounds) {
|
||||
freshVariable.addSubtypeConstraint(upperBound.coneTypeUnsafe()/*, position*/)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRefsOwner
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParametersOwner
|
||||
import org.jetbrains.kotlin.fir.declarations.expandedConeType
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
@@ -56,7 +57,7 @@ private fun receiverExpression(symbol: AbstractFirBasedSymbol<*>, type: ConeKotl
|
||||
class ClassDispatchReceiverValue(klassSymbol: FirClassSymbol<*>) : ReceiverValue {
|
||||
override val type: ConeKotlinType = ConeClassLikeTypeImpl(
|
||||
klassSymbol.toLookupTag(),
|
||||
(klassSymbol.fir as? FirTypeParametersOwner)?.typeParameters?.map { ConeStarProjection }?.toTypedArray().orEmpty(),
|
||||
(klassSymbol.fir as? FirTypeParameterRefsOwner)?.typeParameters?.map { ConeStarProjection }?.toTypedArray().orEmpty(),
|
||||
isNullable = false
|
||||
)
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRefsOwner
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParametersOwner
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeProjection
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirTypePlaceholderProjection
|
||||
@@ -33,7 +34,7 @@ internal object MapTypeArguments : ResolutionStage() {
|
||||
return
|
||||
}
|
||||
|
||||
val owner = candidate.symbol.fir as FirTypeParametersOwner
|
||||
val owner = candidate.symbol.fir as FirTypeParameterRefsOwner
|
||||
|
||||
if (typeArguments.size == owner.typeParameters.size) {
|
||||
candidate.typeArgumentMapping = TypeArgumentMapping.Mapped(typeArguments)
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.fir.firEffectiveVisibility
|
||||
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
import org.jetbrains.kotlin.fir.visitors.compose
|
||||
import org.jetbrains.kotlin.fir.visitors.transformSingle
|
||||
|
||||
@Deprecated("Should be used just once from createTransformerByPhase", level = DeprecationLevel.WARNING)
|
||||
class FirStatusResolveTransformerAdapter : FirTransformer<Nothing?>() {
|
||||
@@ -71,7 +72,7 @@ private class FirStatusResolveTransformer(override val session: FirSession) :
|
||||
override fun transformRegularClass(regularClass: FirRegularClass, data: FirDeclarationStatus?): CompositeTransformResult<FirStatement> {
|
||||
regularClass.transformStatus(this, regularClass.resolveStatus(regularClass.status, containingClass, isLocal = false))
|
||||
return storeClass(regularClass) {
|
||||
regularClass.typeParameters.forEach { transformDeclaration(it, data) }
|
||||
regularClass.typeParameters.forEach { it.transformSingle(this, data) }
|
||||
transformDeclaration(regularClass, data)
|
||||
} as CompositeTransformResult<FirStatement>
|
||||
}
|
||||
@@ -119,6 +120,13 @@ private class FirStatusResolveTransformer(override val session: FirSession) :
|
||||
return transformDeclaration(valueParameter, data) as CompositeTransformResult<FirStatement>
|
||||
}
|
||||
|
||||
override fun transformTypeParameter(
|
||||
typeParameter: FirTypeParameter,
|
||||
data: FirDeclarationStatus?
|
||||
): CompositeTransformResult<FirDeclaration> {
|
||||
return transformDeclaration(typeParameter, data)
|
||||
}
|
||||
|
||||
override fun transformBlock(block: FirBlock, data: FirDeclarationStatus?): CompositeTransformResult<FirStatement> {
|
||||
return block.compose()
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransformer)
|
||||
if (declaration.typeParameters.isEmpty()) return l()
|
||||
|
||||
for (typeParameter in declaration.typeParameters) {
|
||||
typeParameter.replaceResolvePhase(FirResolvePhase.STATUS)
|
||||
(typeParameter as? FirTypeParameter)?.replaceResolvePhase(FirResolvePhase.STATUS)
|
||||
typeParameter.transformChildren(transformer, ResolutionMode.ContextIndependent)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ package org.jetbrains.kotlin.fir.resolve.transformers.body.resolve
|
||||
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParametersOwner
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRefsOwner
|
||||
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic
|
||||
@@ -314,7 +315,7 @@ class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransformer) :
|
||||
type is ConeTypeParameterType ||
|
||||
baseTypeArguments?.isEmpty() != false ||
|
||||
(type is ConeClassLikeType &&
|
||||
(type.lookupTag.toSymbol(session)?.fir as? FirTypeParametersOwner)?.typeParameters?.isEmpty() == true)
|
||||
(type.lookupTag.toSymbol(session)?.fir as? FirTypeParameterRefsOwner)?.typeParameters?.isEmpty() == true)
|
||||
) {
|
||||
this
|
||||
} else {
|
||||
@@ -480,7 +481,7 @@ class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransformer) :
|
||||
val symbol = lhs.symbol
|
||||
val typeRef =
|
||||
symbol?.constructType(
|
||||
Array((symbol.phasedFir as? FirTypeParametersOwner)?.typeParameters?.size ?: 0) {
|
||||
Array((symbol.phasedFir as? FirTypeParameterRefsOwner)?.typeParameters?.size ?: 0) {
|
||||
ConeStarProjection
|
||||
},
|
||||
isNullable = false,
|
||||
@@ -636,7 +637,8 @@ class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransformer) :
|
||||
val expandedSupertype = supertype.fullyExpandedType(session)
|
||||
val symbol =
|
||||
expandedSupertype.lookupTag.toSymbol(session) as? FirClassSymbol<*> ?: return delegatedConstructorCall.compose()
|
||||
val classTypeParametersCount = (symbol.fir as? FirTypeParametersOwner)?.typeParameters?.size ?: 0
|
||||
val classTypeParametersCount =
|
||||
(symbol.fir as? FirTypeParameterRefsOwner)?.typeParameters?.count { it is FirTypeParameter } ?: 0
|
||||
typeArguments = expandedSupertype.typeArguments
|
||||
.takeLast(classTypeParametersCount) // Hack for KT-37525
|
||||
.takeIf { it.isNotEmpty() }
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
package org.jetbrains.kotlin.fir.scopes.impl
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||
import org.jetbrains.kotlin.fir.scopes.FirTypeParameterScope
|
||||
|
||||
class FirMemberTypeParameterScope(callableMember: FirMemberDeclaration) : FirTypeParameterScope() {
|
||||
override val typeParameters = callableMember.typeParameters.groupBy { it.name }
|
||||
override val typeParameters = callableMember.typeParameters.filterIsInstance<FirTypeParameter>().groupBy { it.name }
|
||||
}
|
||||
@@ -522,7 +522,7 @@ class ConeTypeCheckerContext(
|
||||
else -> null
|
||||
}
|
||||
|
||||
val substitutor = if (declaration is FirTypeParametersOwner) {
|
||||
val substitutor = if (declaration is FirTypeParameterRefsOwner) {
|
||||
val substitution =
|
||||
declaration.typeParameters.zip(type.typeArguments).associate { (parameter, argument) ->
|
||||
parameter.symbol to ((argument as? ConeKotlinTypeProjection)?.type
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.types
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.FirSessionComponent
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClassLikeDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRefsOwner
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParametersOwner
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
|
||||
@@ -58,7 +59,7 @@ class FirCorrespondingSupertypesCache(private val session: FirSession) : FirSess
|
||||
val subtypeFirClass: FirClassLikeDeclaration<*> = subtypeClassSymbol.fir
|
||||
|
||||
val defaultType = subtypeClassSymbol.toLookupTag().constructClassType(
|
||||
(subtypeFirClass as? FirTypeParametersOwner)?.typeParameters?.map {
|
||||
(subtypeFirClass as? FirTypeParameterRefsOwner)?.typeParameters?.map {
|
||||
it.symbol.toLookupTag().constructType(emptyArray(), isNullable = false)
|
||||
}?.toTypedArray().orEmpty(),
|
||||
isNullable = false
|
||||
|
||||
@@ -182,7 +182,7 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM
|
||||
}
|
||||
}
|
||||
|
||||
private fun List<FirTypeParameter>.renderTypeParameters() {
|
||||
private fun List<FirTypeParameterRef>.renderTypeParameters() {
|
||||
if (isNotEmpty()) {
|
||||
print("<")
|
||||
renderSeparated()
|
||||
@@ -198,6 +198,10 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitTypeParameterRef(typeParameterRef: FirTypeParameterRef) {
|
||||
typeParameterRef.symbol.fir.accept(this)
|
||||
}
|
||||
|
||||
override fun visitMemberDeclaration(memberDeclaration: FirMemberDeclaration) {
|
||||
memberDeclaration.annotations.renderAnnotations()
|
||||
if (memberDeclaration !is FirProperty || !memberDeclaration.isLocal) {
|
||||
|
||||
@@ -36,13 +36,13 @@ abstract class FirDefaultPropertyAccessor(
|
||||
session,
|
||||
resolvePhase = FirResolvePhase.RAW_FIR,
|
||||
propertyTypeRef,
|
||||
typeParameters = mutableListOf(),
|
||||
valueParameters,
|
||||
body = null,
|
||||
symbol,
|
||||
isGetter,
|
||||
FirDeclarationStatusImpl(visibility, Modality.FINAL),
|
||||
annotations = mutableListOf(),
|
||||
typeParameters = mutableListOf(),
|
||||
) {
|
||||
override var resolvePhase = FirResolvePhase.BODY_RESOLVE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user