[FIR] Set source of smart-cast expressions automatically
#KT-55835
This commit is contained in:
committed by
Space Team
parent
9288a96f6d
commit
91dad7b952
@@ -115,7 +115,6 @@ sealed class ImplicitReceiverValue<S : FirBasedSymbol<*>>(
|
||||
val actualReceiverExpression = if (receiverIsSmartcasted) {
|
||||
buildSmartCastExpression {
|
||||
originalExpression = originalReceiverExpression
|
||||
this.source = originalExpression.source?.fakeElement(KtFakeSourceElementKind.SmartCastExpression)
|
||||
smartcastType = buildResolvedTypeRef {
|
||||
source = originalReceiverExpression.typeRef.source?.fakeElement(KtFakeSourceElementKind.SmartCastedTypeRef)
|
||||
type = this@ImplicitReceiverValue.type
|
||||
|
||||
@@ -448,7 +448,6 @@ private fun <T : FirExpression> BodyResolveComponents.transformExpressionUsingSm
|
||||
}
|
||||
return buildSmartCastExpression {
|
||||
originalExpression = expression
|
||||
source = originalExpression.source?.fakeElement(KtFakeSourceElementKind.SmartCastExpression)
|
||||
smartcastType = intersectedTypeRef
|
||||
smartcastTypeWithoutNullableNothing = reducedIntersectedTypeRef
|
||||
this.typesFromSmartCast = typesFromSmartCast
|
||||
@@ -459,7 +458,6 @@ private fun <T : FirExpression> BodyResolveComponents.transformExpressionUsingSm
|
||||
|
||||
return buildSmartCastExpression {
|
||||
originalExpression = expression
|
||||
source = originalExpression.source?.fakeElement(KtFakeSourceElementKind.SmartCastExpression)
|
||||
smartcastType = intersectedTypeRef
|
||||
this.typesFromSmartCast = typesFromSmartCast
|
||||
this.smartcastStability = smartcastStability
|
||||
@@ -637,4 +635,4 @@ fun FirNamedReferenceWithCandidate.toErrorReference(diagnostic: ConeDiagnostic):
|
||||
this.diagnostic = diagnostic
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,6 @@ private fun removeSmartCastTypeForAttemptToFitVisibility(dispatchReceiver: FirEx
|
||||
when {
|
||||
originalType.isNullableType() && !receiverType.isNullableType() ->
|
||||
buildSmartCastExpression {
|
||||
source = originalExpression.source?.fakeElement(KtFakeSourceElementKind.SmartCastExpression)
|
||||
this.originalExpression = originalExpression
|
||||
smartcastType = buildResolvedTypeRef {
|
||||
source = originalExpression.typeRef.source?.fakeElement(KtFakeSourceElementKind.SmartCastedTypeRef)
|
||||
|
||||
+9
-2
@@ -8,7 +8,9 @@
|
||||
package org.jetbrains.kotlin.fir.expressions.builder
|
||||
|
||||
import kotlin.contracts.*
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.fakeElement
|
||||
import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder
|
||||
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
|
||||
import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty
|
||||
@@ -29,7 +31,6 @@ import org.jetbrains.kotlin.types.SmartcastStability
|
||||
|
||||
@FirBuilderDsl
|
||||
class FirSmartCastExpressionBuilder : FirAnnotationContainerBuilder, FirExpressionBuilder {
|
||||
override var source: KtSourceElement? = null
|
||||
override val annotations: MutableList<FirAnnotation> = mutableListOf()
|
||||
override lateinit var typeRef: FirTypeRef
|
||||
lateinit var originalExpression: FirExpression
|
||||
@@ -40,7 +41,6 @@ class FirSmartCastExpressionBuilder : FirAnnotationContainerBuilder, FirExpressi
|
||||
|
||||
override fun build(): FirSmartCastExpression {
|
||||
return FirSmartCastExpressionImpl(
|
||||
source,
|
||||
annotations.toMutableOrEmpty(),
|
||||
typeRef,
|
||||
originalExpression,
|
||||
@@ -51,6 +51,13 @@ class FirSmartCastExpressionBuilder : FirAnnotationContainerBuilder, FirExpressi
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@Deprecated("Modification of 'source' has no impact for FirSmartCastExpressionBuilder", level = DeprecationLevel.HIDDEN)
|
||||
override var source: KtSourceElement?
|
||||
get() = throw IllegalStateException()
|
||||
set(_) {
|
||||
throw IllegalStateException()
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
|
||||
+3
-1
@@ -7,7 +7,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.expressions.impl
|
||||
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.fakeElement
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression
|
||||
@@ -24,7 +26,6 @@ import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty
|
||||
*/
|
||||
|
||||
internal class FirSmartCastExpressionImpl(
|
||||
override val source: KtSourceElement?,
|
||||
override var annotations: MutableOrEmptyList<FirAnnotation>,
|
||||
override var typeRef: FirTypeRef,
|
||||
override var originalExpression: FirExpression,
|
||||
@@ -33,6 +34,7 @@ internal class FirSmartCastExpressionImpl(
|
||||
override var smartcastTypeWithoutNullableNothing: FirTypeRef?,
|
||||
override val smartcastStability: SmartcastStability,
|
||||
) : FirSmartCastExpression() {
|
||||
override val source: KtSourceElement? = originalExpression.source?.fakeElement(KtFakeSourceElementKind.SmartCastExpression)
|
||||
override val isStable: Boolean get() = smartcastStability == SmartcastStability.STABLE_VALUE
|
||||
|
||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||
|
||||
+4
@@ -452,6 +452,10 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
||||
value = "smartcastStability == SmartcastStability.STABLE_VALUE"
|
||||
withGetter = true
|
||||
}
|
||||
default("source") {
|
||||
value = "originalExpression.source?.fakeElement(KtFakeSourceElementKind.SmartCastExpression)"
|
||||
}
|
||||
useTypes(fakeElementImport, fakeSourceElementKindImport)
|
||||
}
|
||||
|
||||
impl(resolvedNamedReference)
|
||||
|
||||
+3
@@ -15,3 +15,6 @@ val resolvedDeclarationStatusImport = ArbitraryImportable("org.jetbrains.kotlin.
|
||||
val buildResolvedTypeRefImport = ArbitraryImportable("org.jetbrains.kotlin.fir.types.builder", "buildResolvedTypeRef")
|
||||
val constructClassTypeImport = ArbitraryImportable("org.jetbrains.kotlin.fir.types", "constructClassType")
|
||||
val toLookupTagImport = ArbitraryImportable("org.jetbrains.kotlin.fir.types", "toLookupTag")
|
||||
|
||||
val fakeSourceElementKindImport = ArbitraryImportable("org.jetbrains.kotlin", "KtFakeSourceElementKind")
|
||||
val fakeElementImport = ArbitraryImportable("org.jetbrains.kotlin", "fakeElement")
|
||||
|
||||
Reference in New Issue
Block a user