[FE] Prohibit actual typealias to certain compiler annotations

^KT-58554
This commit is contained in:
Roman Efremov
2023-07-13 11:29:24 +02:00
committed by Space Team
parent f4a648aa3e
commit a79282cec1
21 changed files with 198 additions and 0 deletions
@@ -1208,6 +1208,17 @@ object LightTreePositioningStrategies {
}
}
val TYPEALIAS_TYPE_REFERENCE: LightTreePositioningStrategy = object : LightTreePositioningStrategy() {
override fun mark(
node: LighterASTNode,
startOffset: Int,
endOffset: Int,
tree: FlyweightCapableTreeStructure<LighterASTNode>
): List<TextRange> {
val nodeToMark = tree.findChildByType(node, KtNodeTypes.TYPE_REFERENCE) ?: node
return markElement(nodeToMark, startOffset, endOffset, tree, node)
}
}
}
fun KtSourceElement.hasValOrVar(): Boolean =
@@ -1031,6 +1031,13 @@ object PositioningStrategies {
}
}
@JvmField
val TYPEALIAS_TYPE_REFERENCE = object : PositioningStrategy<KtTypeAlias>() {
override fun mark(element: KtTypeAlias): List<TextRange> {
return markElement(element.getTypeReference() ?: element)
}
}
/**
* @param locateReferencedName whether to remove any nested parentheses while locating the reference element. This is useful for
* diagnostics on super and unresolved references. For example, with the following, only the part inside the parentheses should be
@@ -384,4 +384,9 @@ object SourceElementPositioningStrategies {
LightTreePositioningStrategies.CALL_ELEMENT_WITH_DOT,
PositioningStrategies.CALL_ELEMENT_WITH_DOT
)
val TYPEALIAS_TYPE_REFERENCE = SourceElementPositioningStrategy(
LightTreePositioningStrategies.TYPEALIAS_TYPE_REFERENCE,
PositioningStrategies.TYPEALIAS_TYPE_REFERENCE,
)
}