[FIR] Simplify ReceiverValue hierarchy
- Get rid of `AbstractExplicitReceiver` (as there is no explicit usages of it) - Get rid of `AbstractExplicitReceiverValue` (as there is only one inheritor of it) - Make `ReceiverValue` an abstract class
This commit is contained in:
committed by
Space Team
parent
6409bf2fe8
commit
26d7494789
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.fir.expressions.builder.buildThisReceiverExpression
|
|||||||
import org.jetbrains.kotlin.fir.references.builder.buildImplicitThisReference
|
import org.jetbrains.kotlin.fir.references.builder.buildImplicitThisReference
|
||||||
import org.jetbrains.kotlin.fir.renderWithType
|
import org.jetbrains.kotlin.fir.renderWithType
|
||||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.scope
|
import org.jetbrains.kotlin.fir.resolve.scope
|
||||||
import org.jetbrains.kotlin.fir.resolve.smartcastScope
|
import org.jetbrains.kotlin.fir.resolve.smartcastScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator
|
import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator
|
||||||
@@ -34,14 +33,13 @@ import org.jetbrains.kotlin.fir.types.*
|
|||||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.types.SmartcastStability
|
import org.jetbrains.kotlin.types.SmartcastStability
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.applyIf
|
|
||||||
|
|
||||||
interface ReceiverValue {
|
abstract class ReceiverValue {
|
||||||
val type: ConeKotlinType
|
abstract val type: ConeKotlinType
|
||||||
|
|
||||||
val receiverExpression: FirExpression
|
abstract val receiverExpression: FirExpression
|
||||||
|
|
||||||
fun scope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? = type.scope(
|
open fun scope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? = type.scope(
|
||||||
useSiteSession = useSiteSession,
|
useSiteSession = useSiteSession,
|
||||||
scopeSession = scopeSession,
|
scopeSession = scopeSession,
|
||||||
fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing,
|
fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing,
|
||||||
@@ -49,23 +47,12 @@ interface ReceiverValue {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class AbstractExplicitReceiver<E : FirExpression> {
|
class ExpressionReceiverValue(override val receiverExpression: FirExpression) : ReceiverValue() {
|
||||||
abstract val explicitReceiver: FirExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class AbstractExplicitReceiverValue<E : FirExpression> : AbstractExplicitReceiver<E>(), ReceiverValue {
|
|
||||||
override val type: ConeKotlinType
|
override val type: ConeKotlinType
|
||||||
// NB: safe cast is necessary here
|
// NB: safe cast is necessary here
|
||||||
get() = explicitReceiver.typeRef.coneTypeSafe()
|
get() = receiverExpression.typeRef.coneTypeSafe()
|
||||||
?: ConeErrorType(ConeIntermediateDiagnostic("No type calculated for: ${explicitReceiver.renderWithType()}")) // TODO: assert here
|
?: ConeErrorType(ConeIntermediateDiagnostic("No type calculated for: ${receiverExpression.renderWithType()}")) // TODO: assert here
|
||||||
|
|
||||||
final override val receiverExpression: FirExpression
|
|
||||||
get() = explicitReceiver
|
|
||||||
}
|
|
||||||
|
|
||||||
class ExpressionReceiverValue(
|
|
||||||
override val explicitReceiver: FirExpression
|
|
||||||
) : AbstractExplicitReceiverValue<FirExpression>(), ReceiverValue {
|
|
||||||
override fun scope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? {
|
override fun scope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? {
|
||||||
var receiverExpr: FirExpression? = receiverExpression
|
var receiverExpr: FirExpression? = receiverExpression
|
||||||
// Unwrap `x!!` to `x` and use the resulted expression to derive receiver type. This is necessary so that smartcast types inside
|
// Unwrap `x!!` to `x` and use the resulted expression to derive receiver type. This is necessary so that smartcast types inside
|
||||||
@@ -99,7 +86,7 @@ sealed class ImplicitReceiverValue<S : FirBasedSymbol<*>>(
|
|||||||
private val mutable: Boolean,
|
private val mutable: Boolean,
|
||||||
val contextReceiverNumber: Int = -1,
|
val contextReceiverNumber: Int = -1,
|
||||||
private val inaccessibleReceiver: Boolean = false
|
private val inaccessibleReceiver: Boolean = false
|
||||||
) : ReceiverValue {
|
) : ReceiverValue() {
|
||||||
final override var type: ConeKotlinType = type
|
final override var type: ConeKotlinType = type
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
|||||||
@@ -116,11 +116,6 @@ class CandidateFactory private constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ReceiverValue?.isCandidateFromCompanionObjectTypeScope(): Boolean {
|
|
||||||
val expressionReceiverValue = this as? ExpressionReceiverValue ?: return false
|
|
||||||
return expressionReceiverValue.explicitReceiver.isCandidateFromCompanionObjectTypeScope()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun FirExpression?.isCandidateFromCompanionObjectTypeScope(): Boolean {
|
private fun FirExpression?.isCandidateFromCompanionObjectTypeScope(): Boolean {
|
||||||
val resolvedQualifier = this as? FirResolvedQualifier ?: return false
|
val resolvedQualifier = this as? FirResolvedQualifier ?: return false
|
||||||
val originClassOfCandidate = this.typeRef.coneType.classId ?: return false
|
val originClassOfCandidate = this.typeRef.coneType.classId ?: return false
|
||||||
|
|||||||
+1
-3
@@ -41,9 +41,7 @@ fun createQualifierReceiver(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class QualifierReceiver(
|
abstract class QualifierReceiver(val explicitReceiver: FirResolvedQualifier) {
|
||||||
final override val explicitReceiver: FirResolvedQualifier
|
|
||||||
) : AbstractExplicitReceiver<FirResolvedQualifier>() {
|
|
||||||
abstract fun classifierScope(): FirScope?
|
abstract fun classifierScope(): FirScope?
|
||||||
abstract fun callableScope(): FirScope?
|
abstract fun callableScope(): FirScope?
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user