KT-44821 [Sealed Interfaces]: when-exhaustiveness failure in IDE
Compiler check for 'when' exhaustiveness requires that module descriptors of a sealed class and its inheritors are the same (reference identity matters). Prior to this commit and under some conditions they were not. Details follow below. Resolution related data structures (resolution facades) are organized into trees (sdks, libs, and modules have their own nodes/facades, module/class descriptors are stored inside). And the trees themselves are put into a map associating so called PlatformAnalysisSettings and GlobalFacades (plays a role of a root). PlatformAnalysisSettings is an abstraction describing target platform and sdk of a module. The more combinations exist for a project the more facades are used. Please, see KotlinCacheService for more details. So why a module can have multiple ModuleDescriptor-s? Every tree mentioned above is an isolated resolution environment containing its own instances of the outer world descriptors. Say, if a project has modules X, Y, Z and we consider X then all three might have their own vision of X, i.e. 3 descriptors exist at a time. What descriptor instance does compiler get? The path starts when the user opens a file in the editor and highlighting pass starts (see usages of ResolutionUtils#analyzeWithAllCompilerChecks). Module descriptor stored in the resolution tree of the file's module gets injected into the compiler's context. Starting from this moment compiler sees other modules through the prism of a single resolution facade (tree). Descriptors residing outside are alien. This commit allows IdeSealedClassInheritorsProvider to figure out what PlatformAnalysisSettings are associated with the resolution facade (read ModuleDescriptor) seen by the compiler. Later on the same facade is used to provide correct instances of sealed inheritors back to the compiler.
This commit is contained in:
@@ -21,8 +21,8 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.KotlinSuppressCache
|
||||
|
||||
interface KotlinCacheService {
|
||||
@@ -36,4 +36,6 @@ interface KotlinCacheService {
|
||||
|
||||
fun getSuppressionCache(): KotlinSuppressCache
|
||||
fun getResolutionFacadeByModuleInfo(moduleInfo: ModuleInfo, platform: TargetPlatform): ResolutionFacade?
|
||||
|
||||
fun getResolutionFacadeByModuleInfo(moduleInfo: ModuleInfo, settings: PlatformAnalysisSettings): ResolutionFacade?
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.caches.resolve
|
||||
|
||||
/**
|
||||
* Regulates which sources should be analyzed together.
|
||||
*
|
||||
* There are exactly two descendants, which are in strong one-to-one correspondence with [ResolutionModeComponent.Mode] (meaning
|
||||
* that after checking value of ResolutionMode, it's safe to downcast settings instance to the respective type):
|
||||
* - [PlatformAnalysisSettingsImpl] should be used iff we're working under [Mode.SEPARATE], and will create separate
|
||||
* facade for each platforms, sdk, builtIns settings and other stuff.
|
||||
* This is the old and stable mode, which should be used by default.
|
||||
*
|
||||
* - [CompositeAnalysisSettings] should be used iff we're working under [Mode.COMPOSITE], and will analyze all sources
|
||||
* together, in one facade.
|
||||
* This mode is new and experimental, and works only together with TypeRefinement facilities in the compiler's frontend.
|
||||
* This mode is currently enabled only for HMPP projects
|
||||
*/
|
||||
interface PlatformAnalysisSettings
|
||||
Reference in New Issue
Block a user