[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
@@ -117,6 +117,7 @@ fun FirTypeRef.resolvedTypeFromPrototype(
return if (type is ConeKotlinErrorType) {
buildErrorTypeRef {
source = this@resolvedTypeFromPrototype.source
this.type = type
diagnostic = type.diagnostic
}
} else {
@@ -217,6 +217,7 @@ fun ConeKotlinType.toFirResolvedTypeRef(
buildErrorTypeRef {
this.source = source
diagnostic = this@toFirResolvedTypeRef.diagnostic
type = this@toFirResolvedTypeRef
this.delegatedTypeRef = delegatedTypeRef
}
} else {
@@ -275,6 +276,7 @@ fun FirTypeRef.withReplacedConeType(
return if (newType is ConeKotlinErrorType) {
buildErrorTypeRef {
source = newSource
type = newType
diagnostic = newType.diagnostic
}
} else {
@@ -107,6 +107,7 @@ class FirCallCompletionResultsWriterTransformer(
} else {
buildErrorTypeRef {
source = calculated.source?.fakeElement(KtFakeSourceElementKind.ImplicitTypeRef)
type = calculated.type
diagnostic = calculated.diagnostic
}
}
@@ -116,6 +116,9 @@ class FirSpecificTypeResolverTransformer(
} else {
buildErrorTypeRef {
source = functionTypeRef.source
if (resolvedType != null) {
type = resolvedType
}
diagnostic = (resolvedType as? ConeClassErrorType)?.diagnostic
?: ConeSimpleDiagnostic("Unresolved functional type: ${functionTypeRef.render()}")
}
@@ -146,9 +149,9 @@ class FirSpecificTypeResolverTransformer(
typeRef.source
}
delegatedTypeRef = typeRef
diagnostic = resolvedType.diagnostic
delegatedTypeRef = typeRef
type = resolvedType
diagnostic = resolvedType.diagnostic
}
}
}
@@ -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")
@@ -10,6 +10,6 @@ fun A.foo() = ""
class A {
fun main() {
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>bar<!>(::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>) <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>checkType<!> { _<String>() }
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>bar<!>(::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>) <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>checkType<!> { _<String>() }
}
}