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