019836e9c7
Fake overrides created by K1, as well as fir2ir in K2, use DEFINED. So this gets rid of a lot of differences in IR text dumps between the K2 normal mode and K2 with IR fake overrides, and will ultimately help in implementing and testing KT-61360. The change in AddContinuationLowering is needed to fix tests like kt47549. When creating anonymous classes for SAM implementations, we're reusing the same fake override building machinery. And since we can't extract any meaningful information from the fake override parameter's origin anymore, we have to get the parameter from the original symbol.
87 lines
2.8 KiB
Kotlin
Vendored
87 lines
2.8 KiB
Kotlin
Vendored
// ISSUE: KT-44814
|
|
// WITH_STDLIB
|
|
// DUMP_IR
|
|
// DUMP_CFG
|
|
// RENDERER_CFG_LEVELS
|
|
|
|
class FlyweightCapableTreeStructure
|
|
|
|
sealed class FirSourceElement {
|
|
abstract val lighterASTNode: LighterASTNode
|
|
abstract val treeStructure: FlyweightCapableTreeStructure
|
|
}
|
|
class FirPsiSourceElement(
|
|
val psi: PsiElement,
|
|
override val lighterASTNode: LighterASTNode,
|
|
override val treeStructure: FlyweightCapableTreeStructure
|
|
) : FirSourceElement()
|
|
class FirLightSourceElement(
|
|
override val lighterASTNode: LighterASTNode,
|
|
override val treeStructure: FlyweightCapableTreeStructure
|
|
) : FirSourceElement()
|
|
|
|
open class PsiElement
|
|
class ASTNode
|
|
class LighterASTNode(val _children: List<LighterASTNode?> = emptyList()) {
|
|
fun getChildren(treeStructure: FlyweightCapableTreeStructure): List<LighterASTNode?> = _children
|
|
|
|
val tokenType: TokenType = TokenType.MODIFIER_LIST
|
|
}
|
|
|
|
class TokenType {
|
|
companion object {
|
|
val MODIFIER_LIST = TokenType()
|
|
}
|
|
}
|
|
|
|
class KtModifierKeywordToken
|
|
class KtModifierList : PsiElement()
|
|
class KtModifierListOwner : PsiElement() {
|
|
val modifierList: KtModifierList = KtModifierList()
|
|
}
|
|
|
|
internal sealed class FirModifier<Node : Any>(val node: Node, val token: KtModifierKeywordToken) {
|
|
class FirPsiModifier(
|
|
node: ASTNode,
|
|
token: KtModifierKeywordToken
|
|
) : FirModifier<ASTNode>(node, token)
|
|
|
|
class FirLightModifier(
|
|
node: LighterASTNode,
|
|
token: KtModifierKeywordToken,
|
|
val tree: FlyweightCapableTreeStructure
|
|
) : FirModifier<LighterASTNode>(node, token)
|
|
}
|
|
|
|
internal sealed class FirModifierList {
|
|
val modifiers: List<FirModifier<*>> = emptyList()
|
|
|
|
class FirPsiModifierList(val modifierList: KtModifierList) : FirModifierList()
|
|
|
|
class FirLightModifierList(val modifierList: LighterASTNode, val tree: FlyweightCapableTreeStructure) : FirModifierList()
|
|
|
|
companion object {
|
|
fun FirSourceElement?.getModifierList(): FirModifierList? {
|
|
return when (this) {
|
|
null -> null
|
|
is FirPsiSourceElement-> (psi as? KtModifierListOwner)?.modifierList?.let { FirPsiModifierList(it) }
|
|
is FirLightSourceElement -> {
|
|
val modifierListNode = lighterASTNode.getChildren(treeStructure).find { it?.tokenType == TokenType.MODIFIER_LIST }
|
|
?: return null // error is here
|
|
FirLightModifierList(modifierListNode, treeStructure)
|
|
}
|
|
}
|
|
}
|
|
|
|
fun boxImpl(): String {
|
|
val sourceElement: FirSourceElement? = FirLightSourceElement(LighterASTNode(listOf(LighterASTNode())), FlyweightCapableTreeStructure())
|
|
val result = sourceElement.getModifierList()
|
|
return if (result is FirLightModifierList) "OK" else "Fail"
|
|
}
|
|
}
|
|
}
|
|
|
|
fun box(): String {
|
|
return FirModifierList.boxImpl()
|
|
}
|