[AA] Render types in sealed inheritors tests as fully expanded types
- This avoids discrepancies between Standalone and IDE mode for sealed inheritor tests with type aliases from libraries, because in Standalone mode, libraries are deserialized with fully expanded types, while in IDE mode, libraries are deserialized from stubs, where type aliases are currently not expanded. ^KT-66013
This commit is contained in:
committed by
Space Team
parent
2e00879fe1
commit
32337c8255
+27
-1
@@ -6,6 +6,9 @@
|
||||
package org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.inheritorsProvider
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.SymbolByFqName
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.impl.KtDeclarationRendererForSource
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.impl.KtTypeRendererForSource
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.renderers.KtUsualClassTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtNamedClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiBasedTest
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
@@ -21,7 +24,30 @@ abstract class AbstractSealedInheritorsTest : AbstractAnalysisApiBasedTest() {
|
||||
?: error("Expected a single named class to be specified.")
|
||||
|
||||
classSymbol.getSealedClassInheritors().joinToString("\n\n") { inheritor ->
|
||||
"${inheritor.classIdIfNonLocal!!}\n${inheritor.render()}"
|
||||
// Render sealed inheritor supertypes as fully expanded types to avoid discrepancies between Standalone and IDE mode.
|
||||
//
|
||||
// Assume the following code is compiled to a library:
|
||||
//
|
||||
// ```
|
||||
// open class C
|
||||
// typealias T = C
|
||||
// class A : T()
|
||||
// ```
|
||||
//
|
||||
// The supertype of `A` will be different in Standalone and IDE mode:
|
||||
//
|
||||
// - Standalone: The compiled library contains fully expanded types, so `A`'s supertype is `C`.
|
||||
// - IDE: Symbols from libraries are deserialized from stubs, where type aliases are currently not fully expanded, so
|
||||
// `A`'s supertype is `T`.
|
||||
//
|
||||
// We want to render `class A : C()` in both cases, so we need to expand the type alias.
|
||||
val declarationRenderer = KtDeclarationRendererForSource.WITH_QUALIFIED_NAMES.with {
|
||||
typeRenderer = KtTypeRendererForSource.WITH_QUALIFIED_NAMES.with {
|
||||
usualClassTypeRenderer = KtUsualClassTypeRenderer.AS_FULLY_EXPANDED_CLASS_TYPE_WITH_TYPE_ARGUMENTS
|
||||
}
|
||||
}
|
||||
|
||||
"${inheritor.classIdIfNonLocal!!}\n${inheritor.render(declarationRenderer)}"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user