[LL] Search sealed inheritors in the base context module of a dangling module
- `LLSealedInheritorsProvider` should query the direct inheritors
provider with the original source `KtClass` and scope. But
`contextModule` can still be a dangling module, since a code fragment
can have a dangling module as a context module. Only if we take the
base context module can we be sure that we're actually searching with
the original source class and scope.
^KT-76952
diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/providers/LLSealedInheritorsProvider.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/providers/LLSealedInheritorsProvider.kt
index 0efac02..4175f96 100644
--- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/providers/LLSealedInheritorsProvider.kt
+++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/providers/LLSealedInheritorsProvider.kt
@@ -10,6 +10,7 @@
import org.jetbrains.kotlin.analysis.api.platform.declarations.KotlinDirectInheritorsProvider
import org.jetbrains.kotlin.analysis.api.platform.projectStructure.KotlinModuleDependentsProvider
import org.jetbrains.kotlin.analysis.api.projectStructure.KaDanglingFileModule
+import org.jetbrains.kotlin.analysis.api.projectStructure.baseContextModule
import org.jetbrains.kotlin.analysis.low.level.api.fir.projectStructure.llFirModuleData
import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.LLFirSessionCache
import org.jetbrains.kotlin.analysis.low.level.api.fir.symbolProviders.symbolProvider
@@ -74,9 +75,9 @@
private fun searchInheritors(firClass: FirClass): List<ClassId> {
val (targetModule, targetFirClass) = when (val classModule = firClass.llFirModuleData.ktModule) {
is KaDanglingFileModule -> {
- // Since we are searching for inheritors in the `contextModule`'s scope, we need to search for inheritors of the *original*
+ // Since we are searching for inheritors in the context module's scope, we need to search for inheritors of the *original*
// FIR class, not the dangling FIR class.
- val contextModule = classModule.contextModule
+ val contextModule = classModule.baseContextModule
val contextSession = LLFirSessionCache.getInstance(project).getSession(contextModule, preferBinary = true)
val originalFirSymbol = contextSession.symbolProvider.getClassLikeSymbolByClassId(firClass.classId)
val originalFirClass = originalFirSymbol?.fir as? FirClass ?: return emptyList()