[FIR] Initialize type for annotation arguments during deserialization

Get rid of IrErrorTypeImpl creating in FIR2IR
This commit is contained in:
Ivan Kochurkin
2022-04-27 15:57:29 +03:00
parent 0ef043b074
commit ad7c213ab2
18 changed files with 133 additions and 54 deletions
@@ -25,24 +25,19 @@ import org.jetbrains.kotlin.fir.visitors.*
@FirBuilderDsl
class FirClassReferenceExpressionBuilder : FirAnnotationContainerBuilder, FirExpressionBuilder {
override var source: KtSourceElement? = null
override var typeRef: FirTypeRef = FirImplicitTypeRefImpl(null)
override val annotations: MutableList<FirAnnotation> = mutableListOf()
lateinit var classTypeRef: FirTypeRef
override fun build(): FirClassReferenceExpression {
return FirClassReferenceExpressionImpl(
source,
typeRef,
annotations,
classTypeRef,
)
}
@Deprecated("Modification of 'typeRef' has no impact for FirClassReferenceExpressionBuilder", level = DeprecationLevel.HIDDEN)
override var typeRef: FirTypeRef
get() = throw IllegalStateException()
set(_) {
throw IllegalStateException()
}
}
@OptIn(ExperimentalContracts::class)
@@ -28,24 +28,19 @@ import org.jetbrains.kotlin.fir.visitors.*
@FirBuilderDsl
class FirGetClassCallBuilder : FirCallBuilder, FirAnnotationContainerBuilder, FirExpressionBuilder {
override var source: KtSourceElement? = null
override var typeRef: FirTypeRef = FirImplicitTypeRefImpl(null)
override val annotations: MutableList<FirAnnotation> = mutableListOf()
override lateinit var argumentList: FirArgumentList
override fun build(): FirGetClassCall {
return FirGetClassCallImpl(
source,
typeRef,
annotations,
argumentList,
)
}
@Deprecated("Modification of 'typeRef' has no impact for FirGetClassCallBuilder", level = DeprecationLevel.HIDDEN)
override var typeRef: FirTypeRef
get() = throw IllegalStateException()
set(_) {
throw IllegalStateException()
}
}
@OptIn(ExperimentalContracts::class)
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.expressions.FirClassReferenceExpression
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImpl
import org.jetbrains.kotlin.fir.visitors.*
/*
@@ -19,11 +18,10 @@ import org.jetbrains.kotlin.fir.visitors.*
internal class FirClassReferenceExpressionImpl(
override val source: KtSourceElement?,
override var typeRef: FirTypeRef,
override val annotations: MutableList<FirAnnotation>,
override var classTypeRef: FirTypeRef,
) : FirClassReferenceExpression() {
override var typeRef: FirTypeRef = FirImplicitTypeRefImpl(null)
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
typeRef.accept(visitor, data)
annotations.forEach { it.accept(visitor, data) }
@@ -11,7 +11,6 @@ import org.jetbrains.kotlin.fir.expressions.FirArgumentList
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.FirGetClassCall
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImpl
import org.jetbrains.kotlin.fir.visitors.*
/*
@@ -21,10 +20,10 @@ import org.jetbrains.kotlin.fir.visitors.*
internal class FirGetClassCallImpl(
override val source: KtSourceElement?,
override var typeRef: FirTypeRef,
override val annotations: MutableList<FirAnnotation>,
override var argumentList: FirArgumentList,
) : FirGetClassCall() {
override var typeRef: FirTypeRef = FirImplicitTypeRefImpl(null)
override val argument: FirExpression get() = argumentList.arguments.first()
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
@@ -366,7 +366,9 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
varargArgumentsExpression,
checkedSafeCallSubject,
safeCallExpression,
arrayOfCall
arrayOfCall,
classReferenceExpression,
getClassCall
)
elementsWithDefaultTypeRef.forEach {
val (element, name) = when (it) {
@@ -561,6 +561,8 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
"FirArrayOfCallImpl",
"FirIntegerLiteralOperatorCallImpl",
"FirContextReceiverImpl",
"FirClassReferenceExpressionImpl",
"FirGetClassCallImpl"
)
configureFieldInAllImplementations(
field = "typeRef",