[FIR] Fix false positive USELESS_CAST on stub types, ^KT-50293 Fixed

This commit is contained in:
Ivan Kochurkin
2022-06-05 21:53:54 +03:00
committed by teamcity
parent 856d14e5f7
commit fd2b4fd497
17 changed files with 34 additions and 24 deletions
@@ -52,7 +52,7 @@ internal class FirErrorFunctionImpl(
override val symbol: FirErrorFunctionSymbol,
) : FirErrorFunction() {
override var status: FirDeclarationStatus = FirResolvedDeclarationStatusImpl.DEFAULT_STATUS_FOR_STATUSLESS_DECLARATIONS
override var returnTypeRef: FirTypeRef = FirErrorTypeRefImpl(null, null, diagnostic)
override var returnTypeRef: FirTypeRef = FirErrorTypeRefImpl(null, null, diagnostic, false)
override val receiverTypeRef: FirTypeRef? get() = null
override var controlFlowGraphReference: FirControlFlowGraphReference? = null
override val body: FirBlock? get() = null
@@ -55,7 +55,7 @@ internal class FirErrorPropertyImpl(
) : FirErrorProperty() {
override val typeParameters: List<FirTypeParameterRef> get() = emptyList()
override var status: FirDeclarationStatus = FirResolvedDeclarationStatusImpl.DEFAULT_STATUS_FOR_STATUSLESS_DECLARATIONS
override var returnTypeRef: FirTypeRef = FirErrorTypeRefImpl(null, null, diagnostic)
override var returnTypeRef: FirTypeRef = FirErrorTypeRefImpl(null, null, diagnostic, false)
override val receiverTypeRef: FirTypeRef? get() = null
override val initializer: FirExpression? get() = null
override val delegate: FirExpression? get() = null
@@ -28,7 +28,7 @@ internal class FirErrorExpressionImpl(
override val diagnostic: ConeDiagnostic,
override var expression: FirExpression?,
) : FirErrorExpression() {
override var typeRef: FirTypeRef = FirErrorTypeRefImpl(source, null, ConeStubDiagnostic(diagnostic))
override var typeRef: FirTypeRef = FirErrorTypeRefImpl(source, null, ConeStubDiagnostic(diagnostic), false)
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
typeRef.accept(visitor, data)
@@ -22,6 +22,7 @@ abstract class FirErrorTypeRef : FirResolvedTypeRef(), FirDiagnosticHolder {
abstract override val annotations: List<FirAnnotation>
abstract override val type: ConeKotlinType
abstract override val delegatedTypeRef: FirTypeRef?
abstract override val isFromStubType: Boolean
abstract override val diagnostic: ConeDiagnostic
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitErrorTypeRef(this, data)
@@ -20,6 +20,7 @@ abstract class FirResolvedTypeRef : FirTypeRef() {
abstract override val annotations: List<FirAnnotation>
abstract val type: ConeKotlinType
abstract val delegatedTypeRef: FirTypeRef?
abstract val isFromStubType: Boolean
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitResolvedTypeRef(this, data)
@@ -30,6 +30,7 @@ class FirResolvedTypeRefBuilder : FirAnnotationContainerBuilder {
override val annotations: MutableList<FirAnnotation> = mutableListOf()
lateinit var type: ConeKotlinType
var delegatedTypeRef: FirTypeRef? = null
var isFromStubType: Boolean = false
@OptIn(FirImplementationDetail::class)
override fun build(): FirResolvedTypeRef {
@@ -38,6 +39,7 @@ class FirResolvedTypeRefBuilder : FirAnnotationContainerBuilder {
annotations,
type,
delegatedTypeRef,
isFromStubType,
)
}
@@ -61,5 +63,6 @@ inline fun buildResolvedTypeRefCopy(original: FirResolvedTypeRef, init: FirResol
copyBuilder.annotations.addAll(original.annotations)
copyBuilder.type = original.type
copyBuilder.delegatedTypeRef = original.delegatedTypeRef
copyBuilder.isFromStubType = original.isFromStubType
return copyBuilder.apply(init).build()
}
@@ -25,6 +25,7 @@ class FirResolvedTypeRefImpl @FirImplementationDetail constructor(
override val annotations: MutableList<FirAnnotation>,
override val type: ConeKotlinType,
override var delegatedTypeRef: FirTypeRef?,
override val isFromStubType: Boolean,
) : FirResolvedTypeRef() {
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
annotations.forEach { it.accept(visitor, data) }