[FIR] Add ability to safe proper ConeKotlinType in FirErrorTypeRef

This is needed for cases when some type ref is resolved to proper type
  but has some diagnostic (e.g. this type is invisible)
This commit is contained in:
Dmitriy Novozhilov
2021-11-23 16:05:49 +03:00
committed by teamcityserver
parent 08b0e17d47
commit f2c319c4ae
10 changed files with 40 additions and 32 deletions
@@ -26,18 +26,28 @@ import org.jetbrains.kotlin.fir.visitors.*
@FirBuilderDsl
class FirErrorTypeRefBuilder : FirAnnotationContainerBuilder {
override var source: KtSourceElement? = null
var type: ConeKotlinType? = null
var delegatedTypeRef: FirTypeRef? = null
lateinit var diagnostic: ConeDiagnostic
override fun build(): FirErrorTypeRef {
return FirErrorTypeRefImpl(
source,
delegatedTypeRef,
diagnostic,
)
val type = this.type
return if (type != null) {
FirErrorTypeRefImpl(
source,
type,
delegatedTypeRef,
diagnostic,
)
} else {
FirErrorTypeRefImpl(
source,
delegatedTypeRef,
diagnostic,
)
}
}
@Deprecated("Modification of 'annotations' has no impact for FirErrorTypeRefBuilder", level = DeprecationLevel.HIDDEN)
override val annotations: MutableList<FirAnnotation> = mutableListOf()
}
@@ -57,6 +67,7 @@ inline fun buildErrorTypeRefCopy(original: FirErrorTypeRef, init: FirErrorTypeRe
}
val copyBuilder = FirErrorTypeRefBuilder()
copyBuilder.source = original.source
copyBuilder.type = original.type
copyBuilder.delegatedTypeRef = original.delegatedTypeRef
copyBuilder.diagnostic = original.diagnostic
return copyBuilder.apply(init).build()
@@ -14,18 +14,19 @@ import org.jetbrains.kotlin.fir.types.FirErrorTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.visitors.*
/*
* This file was generated automatically
* DO NOT MODIFY IT MANUALLY
*/
internal class FirErrorTypeRefImpl(
override val source: KtSourceElement?,
override val type: ConeKotlinType,
override var delegatedTypeRef: FirTypeRef?,
override val diagnostic: ConeDiagnostic,
) : FirErrorTypeRef() {
constructor(source: KtSourceElement?, delegatedTypeRef: FirTypeRef?, diagnostic: ConeDiagnostic) : this(
source,
ConeClassErrorType(diagnostic),
delegatedTypeRef, diagnostic
)
override val annotations: MutableList<FirAnnotation> = mutableListOf()
override val type: ConeKotlinType = ConeClassErrorType(diagnostic)
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
annotations.forEach { it.accept(visitor, data) }
@@ -254,10 +254,6 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
withCopy()
}
builder(errorTypeRef) {
withCopy()
}
builder(functionTypeRef) {
withCopy()
}
@@ -200,15 +200,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
}
}
val errorTypeRefImpl = impl(errorTypeRef) {
default("type", "ConeClassErrorType(diagnostic)")
default("annotations", "mutableListOf()")
useTypes(coneClassErrorTypeType)
default("delegatedTypeRef") {
needAcceptAndTransform = false
}
}
noImpl(errorTypeRef)
impl(property) {
default("isVal") {
@@ -231,7 +223,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
withGetter = true
)
default("returnTypeRef", "FirErrorTypeRefImpl(null, null, diagnostic)")
useTypes(errorTypeRefImpl)
useTypes(errorTypeRefImplType)
}
impl(field) {
@@ -428,13 +420,13 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
impl(errorExpression) {
default("typeRef", "FirErrorTypeRefImpl(source, null, ConeStubDiagnostic(diagnostic))")
useTypes(errorTypeRefImpl, coneStubDiagnosticType)
useTypes(errorTypeRefImplType, coneStubDiagnosticType)
}
impl(errorFunction) {
defaultNull("receiverTypeRef", "body", withGetter = true)
default("returnTypeRef", "FirErrorTypeRefImpl(null, null, diagnostic)")
useTypes(errorTypeRefImpl)
useTypes(errorTypeRefImplType)
}
impl(functionTypeRef)
@@ -98,4 +98,5 @@ val deprecationsPerUseSiteType = type("fir.declarations", "DeprecationsPerUseSit
val emptyAnnotationArgumentMappingType = type("fir.expressions.impl", "FirEmptyAnnotationArgumentMapping")
val firPropertySymbolType = type("fir.symbols.impl", "FirPropertySymbol")
val errorTypeRefImplType = type("fir.types.impl", "FirErrorTypeRefImpl")