diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt index 838cee38737..5e97d441c22 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt @@ -115,7 +115,6 @@ sealed class ImplicitReceiverValue>( 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 diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt index a23dd5e2b0b..8de239a9129 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt @@ -448,7 +448,6 @@ private fun 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 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 } } -} \ No newline at end of file +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/VisibilityUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/VisibilityUtils.kt index c6f81259183..bd506bc277e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/VisibilityUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/VisibilityUtils.kt @@ -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) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirSmartCastExpressionBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirSmartCastExpressionBuilder.kt index bf9180dc76e..0085bccbccd 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirSmartCastExpressionBuilder.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirSmartCastExpressionBuilder.kt @@ -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 = 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) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirSmartCastExpressionImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirSmartCastExpressionImpl.kt index ee297a4db63..82a50790720 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirSmartCastExpressionImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirSmartCastExpressionImpl.kt @@ -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, 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 acceptChildren(visitor: FirVisitor, data: D) { diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt index 65faa71749d..c3cc77bd219 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt @@ -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) diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/importables.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/importables.kt index ad24f1ea228..273b397dba0 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/importables.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/importables.kt @@ -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")