[FIR] Support type code fragments in 'PsiRawFirBuilder'

For type code fragments, which essentially contain a single type
reference, we add a single statement 'null is Type'.

^KT-61332 Fixed
This commit is contained in:
Yan Zhulanow
2024-01-17 20:12:23 +09:00
committed by Space Team
parent 0350533189
commit 7298289e4e
@@ -47,6 +47,7 @@ import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.*
import org.jetbrains.kotlin.psi.stubs.KotlinFileStub
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
import org.jetbrains.kotlin.types.ConstantValueKind
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.expressions.OperatorConventions
import org.jetbrains.kotlin.util.OperatorNameConventions
@@ -1373,6 +1374,7 @@ open class PsiRawFirBuilder(
when (file) {
is KtExpressionCodeFragment -> file.getContentElement()?.toFirBlock() ?: buildEmptyExpressionBlock()
is KtBlockCodeFragment -> configureBlockWithoutBuilding(file.getContentElement()).build()
is KtTypeCodeFragment -> convertTypeCodeFragmentBlock(file)
else -> error("Unexpected code fragment type: ${file::class}")
}
}
@@ -1380,6 +1382,18 @@ open class PsiRawFirBuilder(
}
}
private fun convertTypeCodeFragmentBlock(file: KtTypeCodeFragment): FirBlock {
return buildBlock {
statements += buildTypeOperatorCall {
operation = FirOperation.IS
conversionTypeRef = file.getContentElement().toFirOrErrorType()
argumentList = buildUnaryArgumentList(
buildLiteralExpression(source = null, ConstantValueKind.Null, value = null, setType = false)
)
}
}
}
override fun visitScript(script: KtScript, data: FirElement?): FirElement {
val ktFile = script.containingKtFile
val fileName = ktFile.name