[FIR] Initialize annotations for block for LightTree

This commit is contained in:
Ivan Kochurkin
2022-06-02 15:21:58 +03:00
committed by teamcity
parent 34b5ce21a1
commit 1ac4d68433
3 changed files with 25 additions and 4 deletions
@@ -435,6 +435,7 @@ class ExpressionsConverter(
when (it.tokenType) {
ANNOTATION -> firAnnotationList += declarationsConverter.convertAnnotation(it)
ANNOTATION_ENTRY -> firAnnotationList += declarationsConverter.convertAnnotationEntry(it)
BLOCK -> firExpression = declarationsConverter.convertBlockExpression(it)
else -> if (it.isExpression()) {
context.forwardLabelUsagePermission(annotatedExpression, it)
firExpression = getAsFirExpression(it)
@@ -442,7 +443,7 @@ class ExpressionsConverter(
}
}
val result = firExpression ?: buildErrorExpression(null, ConeNotAnnotationContainer(firExpression?.render() ?: "???"))
val result = firExpression ?: buildErrorExpression(null, ConeNotAnnotationContainer("???"))
require(result is FirAnnotationContainer)
(result.annotations as MutableList<FirAnnotation>) += firAnnotationList
return result
@@ -1149,6 +1150,13 @@ class ExpressionsConverter(
body?.forEachChildren {
when (it.tokenType) {
BLOCK -> firBlock = declarationsConverter.convertBlockExpression(it)
ANNOTATED_EXPRESSION -> {
if (it.getChildNodeByType(BLOCK) != null) {
firBlock = getAsFirExpression(it)
} else {
firStatement = getAsFirExpression(it)
}
}
else -> if (it.isExpression()) firStatement = getAsFirExpression(it)
}
}
@@ -295,8 +295,17 @@ open class RawFirBuilder(
accept(this@Visitor, Unit) as FirBlock
null ->
buildEmptyExpressionBlock()
else ->
FirSingleExpressionBlock(convert())
else -> {
var firBlock: FirBlock? = null
if (this is KtAnnotatedExpression) {
val lastChild = children.lastOrNull()
if (lastChild is KtBlockExpression) {
firBlock = lastChild.toFirBlock()
extractAnnotationsTo(firBlock.annotations as MutableList<FirAnnotation>)
}
}
firBlock ?: FirSingleExpressionBlock(convert())
}
}
private fun KtDeclarationWithBody.buildFirBody(): Pair<FirBlock?, FirContractDescription?> =
@@ -3,8 +3,12 @@
// ISSUE: KT-52175
annotation class Ann
annotation class Ann2
fun test(x: String?) {
if (x != null)
@Ann() { Unit }
@Ann() @Ann2() { Unit } // It should be Block with annotations
if (x != null)
@Ann() @Ann2() Unit // It should be SingleExpressionBlock with annotations
}