FIR: Fix FirSupertypeResolverTransformer for case of redeclarations
When transforming a specific class look for the exact match Otherwise the last redeclaration will be overwritten by the first one
This commit is contained in:
+11
-5
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.lookupSuperTypes
|
||||
import org.jetbrains.kotlin.fir.scopes.FirPosition
|
||||
import org.jetbrains.kotlin.fir.scopes.addImportingScopes
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.*
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirNestedClassifierScope
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
@@ -64,7 +64,7 @@ class FirSupertypeResolverTransformer : FirAbstractTreeTransformer() {
|
||||
|
||||
if (classId in fullyComputed) return classLikeDeclaration
|
||||
|
||||
val visitor = ResolveSuperTypesTask(firSession, classId, file, currentlyComputing, fullyComputed)
|
||||
val visitor = ResolveSuperTypesTask(firSession, classId, file, currentlyComputing, fullyComputed, classLikeDeclaration)
|
||||
file.accept(visitor, null).single
|
||||
|
||||
return visitor.resultingClass
|
||||
@@ -75,7 +75,8 @@ class FirSupertypeResolverTransformer : FirAbstractTreeTransformer() {
|
||||
private val requestedClassId: ClassId,
|
||||
file: FirFile,
|
||||
private val currentlyComputing: MutableSet<ClassId>,
|
||||
private val fullyComputed: MutableSet<ClassId>
|
||||
private val fullyComputed: MutableSet<ClassId>,
|
||||
private val knownFirClassLikeDeclaration: FirClassLikeDeclaration? = null
|
||||
) : FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority = true) {
|
||||
|
||||
lateinit var resultingClass: FirDeclaration
|
||||
@@ -99,7 +100,7 @@ class FirSupertypeResolverTransformer : FirAbstractTreeTransformer() {
|
||||
regularClass.replaceSupertypes(resultingTypeRefs)
|
||||
}
|
||||
|
||||
if (classId == requestedClassId) {
|
||||
if (regularClass.matchesRequestedDeclaration()) {
|
||||
resultingClass = transformedClass
|
||||
return transformedClass.compose()
|
||||
}
|
||||
@@ -107,10 +108,15 @@ class FirSupertypeResolverTransformer : FirAbstractTreeTransformer() {
|
||||
return resolveNestedClassesSupertypes(transformedClass, data)
|
||||
}
|
||||
|
||||
private fun FirClassLikeDeclaration.matchesRequestedDeclaration(): Boolean {
|
||||
if (knownFirClassLikeDeclaration != null) return knownFirClassLikeDeclaration == this
|
||||
return symbol.classId == requestedClassId
|
||||
}
|
||||
|
||||
override fun transformTypeAlias(typeAlias: FirTypeAlias, data: Nothing?): CompositeTransformResult<FirDeclaration> {
|
||||
val classId = typeAlias.symbol.classId
|
||||
// nested type aliases
|
||||
if (requestedClassId != classId || classId in fullyComputed) return typeAlias.compose()
|
||||
if (classId in fullyComputed || !typeAlias.matchesRequestedDeclaration()) return typeAlias.compose()
|
||||
|
||||
return withScopeCleanup {
|
||||
typeAlias.addTypeParametersScope()
|
||||
|
||||
Reference in New Issue
Block a user