[FIR] Sort HMPP dependencies topologically for symbol providers
This fixes an issue where an actual class from an intermediate module has more supertypes than its expect declaration which leads to a false-positive resolution error because a type reference resolves to the expect class. The fix is to sort the dependencies topologically from "most actual" to "most expect" when creating the list of symbol providers. #KT-57369 Fixed
This commit is contained in:
committed by
Space Team
parent
6fe0849402
commit
60b227c519
+8
-1
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.fir.session
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.container.topologicalSort
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.checkers.registerCommonCheckers
|
||||
import org.jetbrains.kotlin.fir.deserialization.ModuleDataProvider
|
||||
@@ -139,7 +140,13 @@ abstract class FirAbstractSessionFactory {
|
||||
|
||||
private fun FirSession.computeDependencyProviderList(moduleData: FirModuleData): List<FirSymbolProvider> {
|
||||
val visited = mutableSetOf<FirSymbolProvider>()
|
||||
return (moduleData.dependencies + moduleData.friendDependencies + moduleData.dependsOnDependencies)
|
||||
|
||||
// dependsOnDependencies can actualize declarations from their dependencies. Because actual declarations can be more specific
|
||||
// (e.g. have additional supertypes), the modules must be ordered from most specific (i.e. actual) to most generic (i.e. expect)
|
||||
// to prevent false positive resolution errors (see KT-57369 for an example).
|
||||
val dependsOnDependencies = topologicalSort(moduleData.dependsOnDependencies) { it.dependsOnDependencies }
|
||||
|
||||
return (moduleData.dependencies + moduleData.friendDependencies + dependsOnDependencies)
|
||||
.mapNotNull { sessionProvider?.getSession(it) }
|
||||
.map { it.symbolProvider }
|
||||
.flatMap { it.flatten(visited, collectSourceProviders = it.session.kind == FirSession.Kind.Source) }
|
||||
|
||||
Reference in New Issue
Block a user