[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:
committed by
teamcityserver
parent
08b0e17d47
commit
f2c319c4ae
@@ -117,6 +117,7 @@ fun FirTypeRef.resolvedTypeFromPrototype(
|
|||||||
return if (type is ConeKotlinErrorType) {
|
return if (type is ConeKotlinErrorType) {
|
||||||
buildErrorTypeRef {
|
buildErrorTypeRef {
|
||||||
source = this@resolvedTypeFromPrototype.source
|
source = this@resolvedTypeFromPrototype.source
|
||||||
|
this.type = type
|
||||||
diagnostic = type.diagnostic
|
diagnostic = type.diagnostic
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ fun ConeKotlinType.toFirResolvedTypeRef(
|
|||||||
buildErrorTypeRef {
|
buildErrorTypeRef {
|
||||||
this.source = source
|
this.source = source
|
||||||
diagnostic = this@toFirResolvedTypeRef.diagnostic
|
diagnostic = this@toFirResolvedTypeRef.diagnostic
|
||||||
|
type = this@toFirResolvedTypeRef
|
||||||
this.delegatedTypeRef = delegatedTypeRef
|
this.delegatedTypeRef = delegatedTypeRef
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -275,6 +276,7 @@ fun FirTypeRef.withReplacedConeType(
|
|||||||
return if (newType is ConeKotlinErrorType) {
|
return if (newType is ConeKotlinErrorType) {
|
||||||
buildErrorTypeRef {
|
buildErrorTypeRef {
|
||||||
source = newSource
|
source = newSource
|
||||||
|
type = newType
|
||||||
diagnostic = newType.diagnostic
|
diagnostic = newType.diagnostic
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+1
@@ -107,6 +107,7 @@ class FirCallCompletionResultsWriterTransformer(
|
|||||||
} else {
|
} else {
|
||||||
buildErrorTypeRef {
|
buildErrorTypeRef {
|
||||||
source = calculated.source?.fakeElement(KtFakeSourceElementKind.ImplicitTypeRef)
|
source = calculated.source?.fakeElement(KtFakeSourceElementKind.ImplicitTypeRef)
|
||||||
|
type = calculated.type
|
||||||
diagnostic = calculated.diagnostic
|
diagnostic = calculated.diagnostic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-3
@@ -116,6 +116,9 @@ class FirSpecificTypeResolverTransformer(
|
|||||||
} else {
|
} else {
|
||||||
buildErrorTypeRef {
|
buildErrorTypeRef {
|
||||||
source = functionTypeRef.source
|
source = functionTypeRef.source
|
||||||
|
if (resolvedType != null) {
|
||||||
|
type = resolvedType
|
||||||
|
}
|
||||||
diagnostic = (resolvedType as? ConeClassErrorType)?.diagnostic
|
diagnostic = (resolvedType as? ConeClassErrorType)?.diagnostic
|
||||||
?: ConeSimpleDiagnostic("Unresolved functional type: ${functionTypeRef.render()}")
|
?: ConeSimpleDiagnostic("Unresolved functional type: ${functionTypeRef.render()}")
|
||||||
}
|
}
|
||||||
@@ -146,9 +149,9 @@ class FirSpecificTypeResolverTransformer(
|
|||||||
typeRef.source
|
typeRef.source
|
||||||
}
|
}
|
||||||
|
|
||||||
delegatedTypeRef = typeRef
|
delegatedTypeRef = typeRef
|
||||||
|
type = resolvedType
|
||||||
diagnostic = resolvedType.diagnostic
|
diagnostic = resolvedType.diagnostic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-6
@@ -26,18 +26,28 @@ import org.jetbrains.kotlin.fir.visitors.*
|
|||||||
@FirBuilderDsl
|
@FirBuilderDsl
|
||||||
class FirErrorTypeRefBuilder : FirAnnotationContainerBuilder {
|
class FirErrorTypeRefBuilder : FirAnnotationContainerBuilder {
|
||||||
override var source: KtSourceElement? = null
|
override var source: KtSourceElement? = null
|
||||||
|
var type: ConeKotlinType? = null
|
||||||
var delegatedTypeRef: FirTypeRef? = null
|
var delegatedTypeRef: FirTypeRef? = null
|
||||||
lateinit var diagnostic: ConeDiagnostic
|
lateinit var diagnostic: ConeDiagnostic
|
||||||
|
|
||||||
override fun build(): FirErrorTypeRef {
|
override fun build(): FirErrorTypeRef {
|
||||||
return FirErrorTypeRefImpl(
|
val type = this.type
|
||||||
source,
|
return if (type != null) {
|
||||||
delegatedTypeRef,
|
FirErrorTypeRefImpl(
|
||||||
diagnostic,
|
source,
|
||||||
)
|
type,
|
||||||
|
delegatedTypeRef,
|
||||||
|
diagnostic,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
FirErrorTypeRefImpl(
|
||||||
|
source,
|
||||||
|
delegatedTypeRef,
|
||||||
|
diagnostic,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Deprecated("Modification of 'annotations' has no impact for FirErrorTypeRefBuilder", level = DeprecationLevel.HIDDEN)
|
@Deprecated("Modification of 'annotations' has no impact for FirErrorTypeRefBuilder", level = DeprecationLevel.HIDDEN)
|
||||||
override val annotations: MutableList<FirAnnotation> = mutableListOf()
|
override val annotations: MutableList<FirAnnotation> = mutableListOf()
|
||||||
}
|
}
|
||||||
@@ -57,6 +67,7 @@ inline fun buildErrorTypeRefCopy(original: FirErrorTypeRef, init: FirErrorTypeRe
|
|||||||
}
|
}
|
||||||
val copyBuilder = FirErrorTypeRefBuilder()
|
val copyBuilder = FirErrorTypeRefBuilder()
|
||||||
copyBuilder.source = original.source
|
copyBuilder.source = original.source
|
||||||
|
copyBuilder.type = original.type
|
||||||
copyBuilder.delegatedTypeRef = original.delegatedTypeRef
|
copyBuilder.delegatedTypeRef = original.delegatedTypeRef
|
||||||
copyBuilder.diagnostic = original.diagnostic
|
copyBuilder.diagnostic = original.diagnostic
|
||||||
return copyBuilder.apply(init).build()
|
return copyBuilder.apply(init).build()
|
||||||
+7
-6
@@ -14,18 +14,19 @@ import org.jetbrains.kotlin.fir.types.FirErrorTypeRef
|
|||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
import org.jetbrains.kotlin.fir.visitors.*
|
import org.jetbrains.kotlin.fir.visitors.*
|
||||||
|
|
||||||
/*
|
|
||||||
* This file was generated automatically
|
|
||||||
* DO NOT MODIFY IT MANUALLY
|
|
||||||
*/
|
|
||||||
|
|
||||||
internal class FirErrorTypeRefImpl(
|
internal class FirErrorTypeRefImpl(
|
||||||
override val source: KtSourceElement?,
|
override val source: KtSourceElement?,
|
||||||
|
override val type: ConeKotlinType,
|
||||||
override var delegatedTypeRef: FirTypeRef?,
|
override var delegatedTypeRef: FirTypeRef?,
|
||||||
override val diagnostic: ConeDiagnostic,
|
override val diagnostic: ConeDiagnostic,
|
||||||
) : FirErrorTypeRef() {
|
) : FirErrorTypeRef() {
|
||||||
|
constructor(source: KtSourceElement?, delegatedTypeRef: FirTypeRef?, diagnostic: ConeDiagnostic) : this(
|
||||||
|
source,
|
||||||
|
ConeClassErrorType(diagnostic),
|
||||||
|
delegatedTypeRef, diagnostic
|
||||||
|
)
|
||||||
|
|
||||||
override val annotations: MutableList<FirAnnotation> = mutableListOf()
|
override val annotations: MutableList<FirAnnotation> = mutableListOf()
|
||||||
override val type: ConeKotlinType = ConeClassErrorType(diagnostic)
|
|
||||||
|
|
||||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||||
annotations.forEach { it.accept(visitor, data) }
|
annotations.forEach { it.accept(visitor, data) }
|
||||||
-4
@@ -254,10 +254,6 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
|
|||||||
withCopy()
|
withCopy()
|
||||||
}
|
}
|
||||||
|
|
||||||
builder(errorTypeRef) {
|
|
||||||
withCopy()
|
|
||||||
}
|
|
||||||
|
|
||||||
builder(functionTypeRef) {
|
builder(functionTypeRef) {
|
||||||
withCopy()
|
withCopy()
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-12
@@ -200,15 +200,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val errorTypeRefImpl = impl(errorTypeRef) {
|
noImpl(errorTypeRef)
|
||||||
default("type", "ConeClassErrorType(diagnostic)")
|
|
||||||
default("annotations", "mutableListOf()")
|
|
||||||
useTypes(coneClassErrorTypeType)
|
|
||||||
default("delegatedTypeRef") {
|
|
||||||
needAcceptAndTransform = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl(property) {
|
impl(property) {
|
||||||
default("isVal") {
|
default("isVal") {
|
||||||
@@ -231,7 +223,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
|||||||
withGetter = true
|
withGetter = true
|
||||||
)
|
)
|
||||||
default("returnTypeRef", "FirErrorTypeRefImpl(null, null, diagnostic)")
|
default("returnTypeRef", "FirErrorTypeRefImpl(null, null, diagnostic)")
|
||||||
useTypes(errorTypeRefImpl)
|
useTypes(errorTypeRefImplType)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl(field) {
|
impl(field) {
|
||||||
@@ -428,13 +420,13 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
|||||||
|
|
||||||
impl(errorExpression) {
|
impl(errorExpression) {
|
||||||
default("typeRef", "FirErrorTypeRefImpl(source, null, ConeStubDiagnostic(diagnostic))")
|
default("typeRef", "FirErrorTypeRefImpl(source, null, ConeStubDiagnostic(diagnostic))")
|
||||||
useTypes(errorTypeRefImpl, coneStubDiagnosticType)
|
useTypes(errorTypeRefImplType, coneStubDiagnosticType)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl(errorFunction) {
|
impl(errorFunction) {
|
||||||
defaultNull("receiverTypeRef", "body", withGetter = true)
|
defaultNull("receiverTypeRef", "body", withGetter = true)
|
||||||
default("returnTypeRef", "FirErrorTypeRefImpl(null, null, diagnostic)")
|
default("returnTypeRef", "FirErrorTypeRefImpl(null, null, diagnostic)")
|
||||||
useTypes(errorTypeRefImpl)
|
useTypes(errorTypeRefImplType)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl(functionTypeRef)
|
impl(functionTypeRef)
|
||||||
|
|||||||
@@ -98,4 +98,5 @@ val deprecationsPerUseSiteType = type("fir.declarations", "DeprecationsPerUseSit
|
|||||||
val emptyAnnotationArgumentMappingType = type("fir.expressions.impl", "FirEmptyAnnotationArgumentMapping")
|
val emptyAnnotationArgumentMappingType = type("fir.expressions.impl", "FirEmptyAnnotationArgumentMapping")
|
||||||
|
|
||||||
val firPropertySymbolType = type("fir.symbols.impl", "FirPropertySymbol")
|
val firPropertySymbolType = type("fir.symbols.impl", "FirPropertySymbol")
|
||||||
|
val errorTypeRefImplType = type("fir.types.impl", "FirErrorTypeRefImpl")
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -10,6 +10,6 @@ fun A.foo() = ""
|
|||||||
|
|
||||||
class A {
|
class A {
|
||||||
fun main() {
|
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>() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user