[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) {
|
val actualReceiverExpression = if (receiverIsSmartcasted) {
|
||||||
buildSmartCastExpression {
|
buildSmartCastExpression {
|
||||||
originalExpression = originalReceiverExpression
|
originalExpression = originalReceiverExpression
|
||||||
this.source = originalExpression.source?.fakeElement(KtFakeSourceElementKind.SmartCastExpression)
|
|
||||||
smartcastType = buildResolvedTypeRef {
|
smartcastType = buildResolvedTypeRef {
|
||||||
source = originalReceiverExpression.typeRef.source?.fakeElement(KtFakeSourceElementKind.SmartCastedTypeRef)
|
source = originalReceiverExpression.typeRef.source?.fakeElement(KtFakeSourceElementKind.SmartCastedTypeRef)
|
||||||
type = this@ImplicitReceiverValue.type
|
type = this@ImplicitReceiverValue.type
|
||||||
|
|||||||
@@ -448,7 +448,6 @@ private fun <T : FirExpression> BodyResolveComponents.transformExpressionUsingSm
|
|||||||
}
|
}
|
||||||
return buildSmartCastExpression {
|
return buildSmartCastExpression {
|
||||||
originalExpression = expression
|
originalExpression = expression
|
||||||
source = originalExpression.source?.fakeElement(KtFakeSourceElementKind.SmartCastExpression)
|
|
||||||
smartcastType = intersectedTypeRef
|
smartcastType = intersectedTypeRef
|
||||||
smartcastTypeWithoutNullableNothing = reducedIntersectedTypeRef
|
smartcastTypeWithoutNullableNothing = reducedIntersectedTypeRef
|
||||||
this.typesFromSmartCast = typesFromSmartCast
|
this.typesFromSmartCast = typesFromSmartCast
|
||||||
@@ -459,7 +458,6 @@ private fun <T : FirExpression> BodyResolveComponents.transformExpressionUsingSm
|
|||||||
|
|
||||||
return buildSmartCastExpression {
|
return buildSmartCastExpression {
|
||||||
originalExpression = expression
|
originalExpression = expression
|
||||||
source = originalExpression.source?.fakeElement(KtFakeSourceElementKind.SmartCastExpression)
|
|
||||||
smartcastType = intersectedTypeRef
|
smartcastType = intersectedTypeRef
|
||||||
this.typesFromSmartCast = typesFromSmartCast
|
this.typesFromSmartCast = typesFromSmartCast
|
||||||
this.smartcastStability = smartcastStability
|
this.smartcastStability = smartcastStability
|
||||||
@@ -637,4 +635,4 @@ fun FirNamedReferenceWithCandidate.toErrorReference(diagnostic: ConeDiagnostic):
|
|||||||
this.diagnostic = diagnostic
|
this.diagnostic = diagnostic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,6 @@ private fun removeSmartCastTypeForAttemptToFitVisibility(dispatchReceiver: FirEx
|
|||||||
when {
|
when {
|
||||||
originalType.isNullableType() && !receiverType.isNullableType() ->
|
originalType.isNullableType() && !receiverType.isNullableType() ->
|
||||||
buildSmartCastExpression {
|
buildSmartCastExpression {
|
||||||
source = originalExpression.source?.fakeElement(KtFakeSourceElementKind.SmartCastExpression)
|
|
||||||
this.originalExpression = originalExpression
|
this.originalExpression = originalExpression
|
||||||
smartcastType = buildResolvedTypeRef {
|
smartcastType = buildResolvedTypeRef {
|
||||||
source = originalExpression.typeRef.source?.fakeElement(KtFakeSourceElementKind.SmartCastedTypeRef)
|
source = originalExpression.typeRef.source?.fakeElement(KtFakeSourceElementKind.SmartCastedTypeRef)
|
||||||
|
|||||||
+9
-2
@@ -8,7 +8,9 @@
|
|||||||
package org.jetbrains.kotlin.fir.expressions.builder
|
package org.jetbrains.kotlin.fir.expressions.builder
|
||||||
|
|
||||||
import kotlin.contracts.*
|
import kotlin.contracts.*
|
||||||
|
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||||
import org.jetbrains.kotlin.KtSourceElement
|
import org.jetbrains.kotlin.KtSourceElement
|
||||||
|
import org.jetbrains.kotlin.fakeElement
|
||||||
import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder
|
import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder
|
||||||
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
|
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
|
||||||
import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty
|
import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty
|
||||||
@@ -29,7 +31,6 @@ import org.jetbrains.kotlin.types.SmartcastStability
|
|||||||
|
|
||||||
@FirBuilderDsl
|
@FirBuilderDsl
|
||||||
class FirSmartCastExpressionBuilder : FirAnnotationContainerBuilder, FirExpressionBuilder {
|
class FirSmartCastExpressionBuilder : FirAnnotationContainerBuilder, FirExpressionBuilder {
|
||||||
override var source: KtSourceElement? = null
|
|
||||||
override val annotations: MutableList<FirAnnotation> = mutableListOf()
|
override val annotations: MutableList<FirAnnotation> = mutableListOf()
|
||||||
override lateinit var typeRef: FirTypeRef
|
override lateinit var typeRef: FirTypeRef
|
||||||
lateinit var originalExpression: FirExpression
|
lateinit var originalExpression: FirExpression
|
||||||
@@ -40,7 +41,6 @@ class FirSmartCastExpressionBuilder : FirAnnotationContainerBuilder, FirExpressi
|
|||||||
|
|
||||||
override fun build(): FirSmartCastExpression {
|
override fun build(): FirSmartCastExpression {
|
||||||
return FirSmartCastExpressionImpl(
|
return FirSmartCastExpressionImpl(
|
||||||
source,
|
|
||||||
annotations.toMutableOrEmpty(),
|
annotations.toMutableOrEmpty(),
|
||||||
typeRef,
|
typeRef,
|
||||||
originalExpression,
|
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)
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
|||||||
+3
-1
@@ -7,7 +7,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.expressions.impl
|
package org.jetbrains.kotlin.fir.expressions.impl
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||||
import org.jetbrains.kotlin.KtSourceElement
|
import org.jetbrains.kotlin.KtSourceElement
|
||||||
|
import org.jetbrains.kotlin.fakeElement
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression
|
import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression
|
||||||
@@ -24,7 +26,6 @@ import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
internal class FirSmartCastExpressionImpl(
|
internal class FirSmartCastExpressionImpl(
|
||||||
override val source: KtSourceElement?,
|
|
||||||
override var annotations: MutableOrEmptyList<FirAnnotation>,
|
override var annotations: MutableOrEmptyList<FirAnnotation>,
|
||||||
override var typeRef: FirTypeRef,
|
override var typeRef: FirTypeRef,
|
||||||
override var originalExpression: FirExpression,
|
override var originalExpression: FirExpression,
|
||||||
@@ -33,6 +34,7 @@ internal class FirSmartCastExpressionImpl(
|
|||||||
override var smartcastTypeWithoutNullableNothing: FirTypeRef?,
|
override var smartcastTypeWithoutNullableNothing: FirTypeRef?,
|
||||||
override val smartcastStability: SmartcastStability,
|
override val smartcastStability: SmartcastStability,
|
||||||
) : FirSmartCastExpression() {
|
) : FirSmartCastExpression() {
|
||||||
|
override val source: KtSourceElement? = originalExpression.source?.fakeElement(KtFakeSourceElementKind.SmartCastExpression)
|
||||||
override val isStable: Boolean get() = smartcastStability == SmartcastStability.STABLE_VALUE
|
override val isStable: Boolean get() = smartcastStability == SmartcastStability.STABLE_VALUE
|
||||||
|
|
||||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||||
|
|||||||
+4
@@ -452,6 +452,10 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
|||||||
value = "smartcastStability == SmartcastStability.STABLE_VALUE"
|
value = "smartcastStability == SmartcastStability.STABLE_VALUE"
|
||||||
withGetter = true
|
withGetter = true
|
||||||
}
|
}
|
||||||
|
default("source") {
|
||||||
|
value = "originalExpression.source?.fakeElement(KtFakeSourceElementKind.SmartCastExpression)"
|
||||||
|
}
|
||||||
|
useTypes(fakeElementImport, fakeSourceElementKindImport)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl(resolvedNamedReference)
|
impl(resolvedNamedReference)
|
||||||
|
|||||||
+3
@@ -15,3 +15,6 @@ val resolvedDeclarationStatusImport = ArbitraryImportable("org.jetbrains.kotlin.
|
|||||||
val buildResolvedTypeRefImport = ArbitraryImportable("org.jetbrains.kotlin.fir.types.builder", "buildResolvedTypeRef")
|
val buildResolvedTypeRefImport = ArbitraryImportable("org.jetbrains.kotlin.fir.types.builder", "buildResolvedTypeRef")
|
||||||
val constructClassTypeImport = ArbitraryImportable("org.jetbrains.kotlin.fir.types", "constructClassType")
|
val constructClassTypeImport = ArbitraryImportable("org.jetbrains.kotlin.fir.types", "constructClassType")
|
||||||
val toLookupTagImport = ArbitraryImportable("org.jetbrains.kotlin.fir.types", "toLookupTag")
|
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