diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/instanceAccessBeforeSuperCall.fir.txt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/instanceAccessBeforeSuperCall.fir.txt index 43f056db648..e90124db008 100644 --- a/compiler/fir/analysis-tests/testData/resolve/diagnostics/instanceAccessBeforeSuperCall.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/instanceAccessBeforeSuperCall.fir.txt @@ -1,6 +1,6 @@ FILE: instanceAccessBeforeSuperCall.kt public final class A : R|kotlin/Any| { - public constructor(x: R|kotlin/Int| = this@R|/A|.R|/A.getSomeInt#|(), other: R|A| = this@R|/A|, header: R|kotlin/String| = this@R|/A|.R|/A.keker#|): R|A| { + public constructor(x: R|kotlin/Int| = R|A|this@R|/A|.R|/A.getSomeInt|(), other: R|A| = this@R|/A|, header: R|kotlin/String| = R|A|this@R|/A|.R|/A.keker|): R|A| { super() } diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/Main.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/Main.kt index 71b4099b427..f925e92c37a 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/Main.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/Main.kt @@ -5,17 +5,17 @@ package org.jetbrains.kotlin.fir.checkers.generator +import org.jetbrains.kotlin.fir.builder.SYNTAX_DIAGNOSTIC_LIST import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.DIAGNOSTICS_LIST import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.JS_DIAGNOSTICS_LIST import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.JVM_DIAGNOSTICS_LIST +import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.NATIVE_DIAGNOSTICS_LIST +import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.ErrorListDiagnosticListRenderer import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.generateDiagnostics import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.types.FirTypeRef import java.io.File -import org.jetbrains.kotlin.fir.builder.SYNTAX_DIAGNOSTIC_LIST -import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.NATIVE_DIAGNOSTICS_LIST -import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.ErrorListDiagnosticListRenderer fun main(args: Array) { val arguments = args.toList() @@ -62,6 +62,7 @@ fun main(args: Array) { alias("DoWhileLoopChecker") alias("ArrayOfCallChecker") alias("ClassReferenceExpressionChecker") + alias("InaccessibleReceiverChecker") } val declarationPackage = "$basePackage.checkers.declaration" diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/ComposedExpressionCheckers.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/ComposedExpressionCheckers.kt index a3f17178685..0c1417142c1 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/ComposedExpressionCheckers.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/ComposedExpressionCheckers.kt @@ -77,6 +77,8 @@ class ComposedExpressionCheckers : ExpressionCheckers() { get() = _arrayOfCallCheckers override val classReferenceExpressionCheckers: Set get() = _classReferenceExpressionCheckers + override val inaccessibleReceiverCheckers: Set + get() = _inaccessibleReceiverCheckers private val _basicExpressionCheckers: MutableSet = mutableSetOf() private val _qualifiedAccessExpressionCheckers: MutableSet = mutableSetOf() @@ -110,6 +112,7 @@ class ComposedExpressionCheckers : ExpressionCheckers() { private val _doWhileLoopCheckers: MutableSet = mutableSetOf() private val _arrayOfCallCheckers: MutableSet = mutableSetOf() private val _classReferenceExpressionCheckers: MutableSet = mutableSetOf() + private val _inaccessibleReceiverCheckers: MutableSet = mutableSetOf() @CheckersComponentInternal fun register(checkers: ExpressionCheckers) { @@ -145,5 +148,6 @@ class ComposedExpressionCheckers : ExpressionCheckers() { _doWhileLoopCheckers += checkers.doWhileLoopCheckers _arrayOfCallCheckers += checkers.arrayOfCallCheckers _classReferenceExpressionCheckers += checkers.classReferenceExpressionCheckers + _inaccessibleReceiverCheckers += checkers.inaccessibleReceiverCheckers } } diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/ExpressionCheckers.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/ExpressionCheckers.kt index 9d455905526..78419a0ece1 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/ExpressionCheckers.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/ExpressionCheckers.kt @@ -49,6 +49,7 @@ abstract class ExpressionCheckers { open val doWhileLoopCheckers: Set = emptySet() open val arrayOfCallCheckers: Set = emptySet() open val classReferenceExpressionCheckers: Set = emptySet() + open val inaccessibleReceiverCheckers: Set = emptySet() @CheckersComponentInternal internal val allBasicExpressionCheckers: Set by lazy { basicExpressionCheckers } @CheckersComponentInternal internal val allQualifiedAccessExpressionCheckers: Set by lazy { qualifiedAccessExpressionCheckers + basicExpressionCheckers } @@ -82,4 +83,5 @@ abstract class ExpressionCheckers { @CheckersComponentInternal internal val allDoWhileLoopCheckers: Set by lazy { doWhileLoopCheckers + loopExpressionCheckers + basicExpressionCheckers } @CheckersComponentInternal internal val allArrayOfCallCheckers: Set by lazy { arrayOfCallCheckers + basicExpressionCheckers + callCheckers } @CheckersComponentInternal internal val allClassReferenceExpressionCheckers: Set by lazy { classReferenceExpressionCheckers + basicExpressionCheckers } + @CheckersComponentInternal internal val allInaccessibleReceiverCheckers: Set by lazy { inaccessibleReceiverCheckers + basicExpressionCheckers } } diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirExpressionCheckerAliases.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirExpressionCheckerAliases.kt index 80c1616b9bf..0c3cd57c1b6 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirExpressionCheckerAliases.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirExpressionCheckerAliases.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.fir.expressions.FirElvisExpression import org.jetbrains.kotlin.fir.expressions.FirEqualityOperatorCall import org.jetbrains.kotlin.fir.expressions.FirFunctionCall import org.jetbrains.kotlin.fir.expressions.FirGetClassCall +import org.jetbrains.kotlin.fir.expressions.FirInaccessibleReceiverExpression import org.jetbrains.kotlin.fir.expressions.FirIntegerLiteralOperatorCall import org.jetbrains.kotlin.fir.expressions.FirLoop import org.jetbrains.kotlin.fir.expressions.FirLoopJump @@ -75,3 +76,4 @@ typealias FirThrowExpressionChecker = FirExpressionChecker typealias FirDoWhileLoopChecker = FirExpressionChecker typealias FirArrayOfCallChecker = FirExpressionChecker typealias FirClassReferenceExpressionChecker = FirExpressionChecker +typealias FirInaccessibleReceiverChecker = FirExpressionChecker diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonExpressionCheckers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonExpressionCheckers.kt index fca51aa1362..3238c2b37d5 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonExpressionCheckers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/CommonExpressionCheckers.kt @@ -162,4 +162,9 @@ object CommonExpressionCheckers : ExpressionCheckers() { get() = setOf( FirUnsupportedArrayLiteralChecker ) + + override val inaccessibleReceiverCheckers: Set + get() = setOf( + FirReceiverAccessBeforeSuperCallChecker, + ) } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirReceiverAccessBeforeSuperCallChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirReceiverAccessBeforeSuperCallChecker.kt new file mode 100644 index 00000000000..2d53b75fac5 --- /dev/null +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirReceiverAccessBeforeSuperCallChecker.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.analysis.checkers.expression + +import org.jetbrains.kotlin.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.diagnostics.reportOn +import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors +import org.jetbrains.kotlin.fir.expressions.FirInaccessibleReceiverExpression +import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression + +object FirReceiverAccessBeforeSuperCallChecker : FirInaccessibleReceiverChecker() { + override fun check(expression: FirInaccessibleReceiverExpression, context: CheckerContext, reporter: DiagnosticReporter) { + val containingCall = context.qualifiedAccessOrAssignmentsOrAnnotationCalls.last() as FirQualifiedAccessExpression + containingCall.run { + require(expression == dispatchReceiver || expression == extensionReceiver || expression in contextReceiverArguments) + } + reporter.reportOn(containingCall.calleeReference.source, FirErrors.INSTANCE_ACCESS_BEFORE_SUPER_CALL, "", context) + } +} diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ExpressionCheckersDiagnosticComponent.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ExpressionCheckersDiagnosticComponent.kt index 456e5facae1..65d8caebe18 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ExpressionCheckersDiagnosticComponent.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ExpressionCheckersDiagnosticComponent.kt @@ -5,14 +5,14 @@ package org.jetbrains.kotlin.fir.analysis.collectors.components +import org.jetbrains.kotlin.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.analysis.CheckersComponentInternal import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.analysis.checkers.expression.ExpressionCheckers import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirExpressionChecker import org.jetbrains.kotlin.fir.analysis.checkersComponent -import org.jetbrains.kotlin.diagnostics.DiagnosticReporter -import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.expressions.* @OptIn(CheckersComponentInternal::class) @@ -83,6 +83,13 @@ class ExpressionCheckersDiagnosticComponent( checkers.allThisReceiverExpressionCheckers.check(thisReceiverExpression, data) } + override fun visitInaccessibleReceiverExpression( + inaccessibleReceiverExpression: FirInaccessibleReceiverExpression, + data: CheckerContext, + ) { + checkers.allInaccessibleReceiverCheckers.check(inaccessibleReceiverExpression, data) + } + override fun visitResolvedQualifier(resolvedQualifier: FirResolvedQualifier, data: CheckerContext) { checkers.allResolvedQualifierCheckers.check(resolvedQualifier, data) } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt index 2cd707548e8..afe6d4f69ef 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt @@ -302,8 +302,6 @@ private fun mapInapplicableCandidateError( isError = rootCause.isError ) - is InaccessibleReceiver -> FirErrors.INSTANCE_ACCESS_BEFORE_SUPER_CALL.createOn(source, "") - else -> genericDiagnostic } }.distinct() diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt index 2968bf9470e..a1a0fb3dc55 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt @@ -632,6 +632,19 @@ class Fir2IrVisitor( return visitQualifiedAccessExpression(thisReceiverExpression, data) } + override fun visitInaccessibleReceiverExpression( + inaccessibleReceiverExpression: FirInaccessibleReceiverExpression, + data: Any?, + ): IrElement { + return inaccessibleReceiverExpression.convertWithOffsets { startOffset, endOffset -> + IrErrorExpressionImpl( + startOffset, endOffset, + inaccessibleReceiverExpression.typeRef.toIrType(), + "Receiver is inaccessible" + ) + } + } + override fun visitSmartCastExpression(smartCastExpression: FirSmartCastExpression, data: Any?): IrElement { // Generate the expression with the original type and then cast it to the smart cast type. val value = convertToIrExpression(smartCastExpression.originalExpression) 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 5d5e8c4cd45..113c991c7d0 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 @@ -11,7 +11,11 @@ import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.copyWithNewSourceKind import org.jetbrains.kotlin.fir.declarations.FirResolvePhase import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic -import org.jetbrains.kotlin.fir.expressions.* +import org.jetbrains.kotlin.fir.expressions.FirCheckNotNullCall +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression +import org.jetbrains.kotlin.fir.expressions.arguments +import org.jetbrains.kotlin.fir.expressions.builder.buildInaccessibleReceiverExpression import org.jetbrains.kotlin.fir.expressions.builder.buildSmartCastExpression import org.jetbrains.kotlin.fir.expressions.builder.buildThisReceiverExpression import org.jetbrains.kotlin.fir.references.builder.buildImplicitThisReference @@ -97,6 +101,7 @@ sealed class ImplicitReceiverValue>( protected val scopeSession: ScopeSession, private val mutable: Boolean, val contextReceiverNumber: Int = -1, + private val inaccessibleReceiver: Boolean = false ) : ReceiverValue { final override var type: ConeKotlinType = type private set @@ -118,7 +123,8 @@ sealed class ImplicitReceiverValue>( override fun scope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? = implicitScope - private val originalReceiverExpression: FirThisReceiverExpression = receiverExpression(boundSymbol, type, contextReceiverNumber) + private val originalReceiverExpression: FirExpression = + receiverExpression(boundSymbol, type, contextReceiverNumber, inaccessibleReceiver) final override var receiverExpression: FirExpression = originalReceiverExpression private set @@ -128,7 +134,7 @@ sealed class ImplicitReceiverValue>( @Deprecated(level = DeprecationLevel.ERROR, message = "Builder inference should not modify implicit receivers. KT-54708") fun updateTypeInBuilderInference(type: ConeKotlinType) { this.type = type - receiverExpression = receiverExpression(boundSymbol, type, contextReceiverNumber) + receiverExpression = receiverExpression(boundSymbol, type, contextReceiverNumber, inaccessibleReceiver) implicitScope = type.scope( useSiteSession = useSiteSession, scopeSession = scopeSession, @@ -176,18 +182,28 @@ private fun receiverExpression( symbol: FirBasedSymbol<*>, type: ConeKotlinType, contextReceiverNumber: Int, -): FirThisReceiverExpression = - buildThisReceiverExpression { - // NB: we can't use `symbol.fir.source` as the source of `this` receiver. For instance, if this is an implicit receiver for a class, - // the entire class itself will be set as a source. If combined with an implicit type operation, a certain assertion, like null - // check assertion, will retrieve source as an assertion message, which is literally the entire class (!). - calleeReference = buildImplicitThisReference { - boundSymbol = symbol - this.contextReceiverNumber = contextReceiverNumber - } - typeRef = type.toFirResolvedTypeRef() - isImplicit = true + inaccessibleReceiver: Boolean +): FirExpression { + // NB: we can't use `symbol.fir.source` as the source of `this` receiver. For instance, if this is an implicit receiver for a class, + // the entire class itself will be set as a source. If combined with an implicit type operation, a certain assertion, like null + // check assertion, will retrieve source as an assertion message, which is literally the entire class (!). + val calleeReference = buildImplicitThisReference { + boundSymbol = symbol + this.contextReceiverNumber = contextReceiverNumber } + val typeRef = type.toFirResolvedTypeRef() + return when (inaccessibleReceiver) { + false -> buildThisReceiverExpression { + this.calleeReference = calleeReference + this.typeRef = typeRef + isImplicit = true + } + true -> buildInaccessibleReceiverExpression { + this.calleeReference = calleeReference + this.typeRef = typeRef + } + } +} class ImplicitDispatchReceiverValue( boundSymbol: FirClassSymbol<*>, @@ -233,7 +249,7 @@ class InaccessibleImplicitReceiverValue( useSiteSession: FirSession, scopeSession: ScopeSession, mutable: Boolean = true, -) : ImplicitReceiverValue>(boundSymbol, type, useSiteSession, scopeSession, mutable) { +) : ImplicitReceiverValue>(boundSymbol, type, useSiteSession, scopeSession, mutable, inaccessibleReceiver = true) { override fun createSnapshot(): ImplicitReceiverValue> { return InaccessibleImplicitReceiverValue(boundSymbol, type, useSiteSession, scopeSession, false) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt index 617cbd98a30..c07841982e4 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt @@ -24,7 +24,6 @@ sealed class CallKind(vararg resolutionSequence: ResolutionStage) { LowerPriorityIfDynamic, ConstraintSystemForks, CheckIncompatibleTypeVariableUpperBounds, - InaccessibleReceiverResolutionStage, ) object SyntheticSelect : CallKind( @@ -60,7 +59,6 @@ sealed class CallKind(vararg resolutionSequence: ResolutionStage) { LowerPriorityIfDynamic, ConstraintSystemForks, CheckIncompatibleTypeVariableUpperBounds, - InaccessibleReceiverResolutionStage, ) object DelegatingConstructorCall : CallKind( @@ -96,7 +94,6 @@ sealed class CallKind(vararg resolutionSequence: ResolutionStage) { CheckIncompatibleTypeVariableUpperBounds, ProcessDynamicExtensionAnnotation, LowerPriorityIfDynamic, - InaccessibleReceiverResolutionStage, ) object SyntheticIdForCallableReferencesResolution : CallKind( diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt index 8fd8401c70d..da72d6bbf9b 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt @@ -712,14 +712,3 @@ internal object ConstraintSystemForks : ResolutionStage() { } } } - -internal object InaccessibleReceiverResolutionStage : ResolutionStage() { - override suspend fun check(candidate: Candidate, callInfo: CallInfo, sink: CheckerSink, context: ResolutionContext) { - if ( - candidate.dispatchReceiverValue is InaccessibleImplicitReceiverValue || - candidate.givenExtensionReceiverOptions.any { it is InaccessibleImplicitReceiverValue } - ) { - sink.yieldDiagnostic(InaccessibleReceiver) - } - } -} diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt index 0d2690cb674..47ede463b10 100644 --- a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt @@ -141,5 +141,3 @@ class NoApplicableValueForContextReceiver( class AmbiguousValuesForContextReceiverParameter( val expectedContextReceiverType: ConeKotlinType, ) : ResolutionDiagnostic(INAPPLICABLE) - -object InaccessibleReceiver : ResolutionDiagnostic(RESOLVED_WITH_ERROR) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirInaccessibleReceiverExpression.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirInaccessibleReceiverExpression.kt new file mode 100644 index 00000000000..737c65b5585 --- /dev/null +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirInaccessibleReceiverExpression.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.expressions + +import org.jetbrains.kotlin.KtSourceElement +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.references.FirReference +import org.jetbrains.kotlin.fir.references.FirThisReference +import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.visitors.* + +/* + * This file was generated automatically + * DO NOT MODIFY IT MANUALLY + */ + +abstract class FirInaccessibleReceiverExpression : FirExpression(), FirResolvable { + abstract override val source: KtSourceElement? + abstract override val typeRef: FirTypeRef + abstract override val annotations: List + abstract override val calleeReference: FirThisReference + + override fun accept(visitor: FirVisitor, data: D): R = visitor.visitInaccessibleReceiverExpression(this, data) + + @Suppress("UNCHECKED_CAST") + override fun transform(transformer: FirTransformer, data: D): E = + transformer.transformInaccessibleReceiverExpression(this, data) as E + + abstract override fun replaceTypeRef(newTypeRef: FirTypeRef) + + abstract override fun replaceAnnotations(newAnnotations: List) + + abstract fun replaceCalleeReference(newCalleeReference: FirThisReference) + + abstract override fun replaceCalleeReference(newCalleeReference: FirReference) + + abstract override fun transformAnnotations(transformer: FirTransformer, data: D): FirInaccessibleReceiverExpression + + abstract override fun transformCalleeReference(transformer: FirTransformer, data: D): FirInaccessibleReceiverExpression +} diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirInaccessibleReceiverExpressionBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirInaccessibleReceiverExpressionBuilder.kt new file mode 100644 index 00000000000..d3d07c32905 --- /dev/null +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirInaccessibleReceiverExpressionBuilder.kt @@ -0,0 +1,53 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +@file:Suppress("DuplicatedCode") + +package org.jetbrains.kotlin.fir.expressions.builder + +import kotlin.contracts.* +import org.jetbrains.kotlin.KtSourceElement +import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder +import org.jetbrains.kotlin.fir.builder.FirBuilderDsl +import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty +import org.jetbrains.kotlin.fir.expressions.FirAnnotation +import org.jetbrains.kotlin.fir.expressions.FirInaccessibleReceiverExpression +import org.jetbrains.kotlin.fir.expressions.builder.FirExpressionBuilder +import org.jetbrains.kotlin.fir.expressions.impl.FirInaccessibleReceiverExpressionImpl +import org.jetbrains.kotlin.fir.references.FirReference +import org.jetbrains.kotlin.fir.references.FirThisReference +import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.visitors.* + +/* + * This file was generated automatically + * DO NOT MODIFY IT MANUALLY + */ + +@FirBuilderDsl +class FirInaccessibleReceiverExpressionBuilder : FirAnnotationContainerBuilder, FirExpressionBuilder { + override var source: KtSourceElement? = null + override lateinit var typeRef: FirTypeRef + override val annotations: MutableList = mutableListOf() + lateinit var calleeReference: FirThisReference + + override fun build(): FirInaccessibleReceiverExpression { + return FirInaccessibleReceiverExpressionImpl( + source, + typeRef, + annotations.toMutableOrEmpty(), + calleeReference, + ) + } + +} + +@OptIn(ExperimentalContracts::class) +inline fun buildInaccessibleReceiverExpression(init: FirInaccessibleReceiverExpressionBuilder.() -> Unit): FirInaccessibleReceiverExpression { + contract { + callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE) + } + return FirInaccessibleReceiverExpressionBuilder().apply(init).build() +} diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirInaccessibleReceiverExpressionImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirInaccessibleReceiverExpressionImpl.kt new file mode 100644 index 00000000000..1cd7cfbc5e0 --- /dev/null +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirInaccessibleReceiverExpressionImpl.kt @@ -0,0 +1,70 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +@file:Suppress("DuplicatedCode") + +package org.jetbrains.kotlin.fir.expressions.impl + +import org.jetbrains.kotlin.KtSourceElement +import org.jetbrains.kotlin.fir.expressions.FirAnnotation +import org.jetbrains.kotlin.fir.expressions.FirInaccessibleReceiverExpression +import org.jetbrains.kotlin.fir.references.FirReference +import org.jetbrains.kotlin.fir.references.FirThisReference +import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.visitors.* +import org.jetbrains.kotlin.fir.MutableOrEmptyList +import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty + +/* + * This file was generated automatically + * DO NOT MODIFY IT MANUALLY + */ + +internal class FirInaccessibleReceiverExpressionImpl( + override val source: KtSourceElement?, + override var typeRef: FirTypeRef, + override var annotations: MutableOrEmptyList, + override var calleeReference: FirThisReference, +) : FirInaccessibleReceiverExpression() { + override fun acceptChildren(visitor: FirVisitor, data: D) { + typeRef.accept(visitor, data) + annotations.forEach { it.accept(visitor, data) } + calleeReference.accept(visitor, data) + } + + override fun transformChildren(transformer: FirTransformer, data: D): FirInaccessibleReceiverExpressionImpl { + typeRef = typeRef.transform(transformer, data) + transformAnnotations(transformer, data) + transformCalleeReference(transformer, data) + return this + } + + override fun transformAnnotations(transformer: FirTransformer, data: D): FirInaccessibleReceiverExpressionImpl { + annotations.transformInplace(transformer, data) + return this + } + + override fun transformCalleeReference(transformer: FirTransformer, data: D): FirInaccessibleReceiverExpressionImpl { + calleeReference = calleeReference.transform(transformer, data) + return this + } + + override fun replaceTypeRef(newTypeRef: FirTypeRef) { + typeRef = newTypeRef + } + + override fun replaceAnnotations(newAnnotations: List) { + annotations = newAnnotations.toMutableOrEmpty() + } + + override fun replaceCalleeReference(newCalleeReference: FirThisReference) { + calleeReference = newCalleeReference + } + + override fun replaceCalleeReference(newCalleeReference: FirReference) { + require(newCalleeReference is FirThisReference) + replaceCalleeReference(newCalleeReference) + } +} diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitor.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitor.kt index bd0f21bc38c..c044539fe33 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitor.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitor.kt @@ -109,6 +109,7 @@ import org.jetbrains.kotlin.fir.expressions.FirMultiDelegatedConstructorCall import org.jetbrains.kotlin.fir.expressions.FirComponentCall import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess import org.jetbrains.kotlin.fir.expressions.FirThisReceiverExpression +import org.jetbrains.kotlin.fir.expressions.FirInaccessibleReceiverExpression import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression import org.jetbrains.kotlin.fir.expressions.FirSafeCallExpression import org.jetbrains.kotlin.fir.expressions.FirCheckedSafeCallSubject diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitorVoid.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitorVoid.kt index ce98df0d081..030d69f8dd7 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitorVoid.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirDefaultVisitorVoid.kt @@ -109,6 +109,7 @@ import org.jetbrains.kotlin.fir.expressions.FirMultiDelegatedConstructorCall import org.jetbrains.kotlin.fir.expressions.FirComponentCall import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess import org.jetbrains.kotlin.fir.expressions.FirThisReceiverExpression +import org.jetbrains.kotlin.fir.expressions.FirInaccessibleReceiverExpression import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression import org.jetbrains.kotlin.fir.expressions.FirSafeCallExpression import org.jetbrains.kotlin.fir.expressions.FirCheckedSafeCallSubject diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirTransformer.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirTransformer.kt index f63d9f0d19b..4e9d086a94f 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirTransformer.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirTransformer.kt @@ -109,6 +109,7 @@ import org.jetbrains.kotlin.fir.expressions.FirMultiDelegatedConstructorCall import org.jetbrains.kotlin.fir.expressions.FirComponentCall import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess import org.jetbrains.kotlin.fir.expressions.FirThisReceiverExpression +import org.jetbrains.kotlin.fir.expressions.FirInaccessibleReceiverExpression import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression import org.jetbrains.kotlin.fir.expressions.FirSafeCallExpression import org.jetbrains.kotlin.fir.expressions.FirCheckedSafeCallSubject @@ -578,6 +579,10 @@ abstract class FirTransformer : FirVisitor() { return transformElement(thisReceiverExpression, data) } + open fun transformInaccessibleReceiverExpression(inaccessibleReceiverExpression: FirInaccessibleReceiverExpression, data: D): FirStatement { + return transformElement(inaccessibleReceiverExpression, data) + } + open fun transformSmartCastExpression(smartCastExpression: FirSmartCastExpression, data: D): FirStatement { return transformElement(smartCastExpression, data) } @@ -1182,6 +1187,10 @@ abstract class FirTransformer : FirVisitor() { return transformThisReceiverExpression(thisReceiverExpression, data) } + final override fun visitInaccessibleReceiverExpression(inaccessibleReceiverExpression: FirInaccessibleReceiverExpression, data: D): FirStatement { + return transformInaccessibleReceiverExpression(inaccessibleReceiverExpression, data) + } + final override fun visitSmartCastExpression(smartCastExpression: FirSmartCastExpression, data: D): FirStatement { return transformSmartCastExpression(smartCastExpression, data) } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitor.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitor.kt index 2cdce485a46..2fd984e2bd8 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitor.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitor.kt @@ -109,6 +109,7 @@ import org.jetbrains.kotlin.fir.expressions.FirMultiDelegatedConstructorCall import org.jetbrains.kotlin.fir.expressions.FirComponentCall import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess import org.jetbrains.kotlin.fir.expressions.FirThisReceiverExpression +import org.jetbrains.kotlin.fir.expressions.FirInaccessibleReceiverExpression import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression import org.jetbrains.kotlin.fir.expressions.FirSafeCallExpression import org.jetbrains.kotlin.fir.expressions.FirCheckedSafeCallSubject @@ -371,6 +372,8 @@ abstract class FirVisitor { open fun visitThisReceiverExpression(thisReceiverExpression: FirThisReceiverExpression, data: D): R = visitElement(thisReceiverExpression, data) + open fun visitInaccessibleReceiverExpression(inaccessibleReceiverExpression: FirInaccessibleReceiverExpression, data: D): R = visitElement(inaccessibleReceiverExpression, data) + open fun visitSmartCastExpression(smartCastExpression: FirSmartCastExpression, data: D): R = visitElement(smartCastExpression, data) open fun visitSafeCallExpression(safeCallExpression: FirSafeCallExpression, data: D): R = visitElement(safeCallExpression, data) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitorVoid.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitorVoid.kt index b69ba2da979..485bdfa9475 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitorVoid.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitorVoid.kt @@ -109,6 +109,7 @@ import org.jetbrains.kotlin.fir.expressions.FirMultiDelegatedConstructorCall import org.jetbrains.kotlin.fir.expressions.FirComponentCall import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess import org.jetbrains.kotlin.fir.expressions.FirThisReceiverExpression +import org.jetbrains.kotlin.fir.expressions.FirInaccessibleReceiverExpression import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression import org.jetbrains.kotlin.fir.expressions.FirSafeCallExpression import org.jetbrains.kotlin.fir.expressions.FirCheckedSafeCallSubject @@ -577,6 +578,10 @@ abstract class FirVisitorVoid : FirVisitor() { visitElement(thisReceiverExpression) } + open fun visitInaccessibleReceiverExpression(inaccessibleReceiverExpression: FirInaccessibleReceiverExpression) { + visitElement(inaccessibleReceiverExpression) + } + open fun visitSmartCastExpression(smartCastExpression: FirSmartCastExpression) { visitElement(smartCastExpression) } @@ -1181,6 +1186,10 @@ abstract class FirVisitorVoid : FirVisitor() { visitThisReceiverExpression(thisReceiverExpression) } + final override fun visitInaccessibleReceiverExpression(inaccessibleReceiverExpression: FirInaccessibleReceiverExpression, data: Nothing?) { + visitInaccessibleReceiverExpression(inaccessibleReceiverExpression) + } + final override fun visitSmartCastExpression(smartCastExpression: FirSmartCastExpression, data: Nothing?) { visitSmartCastExpression(smartCastExpression) } diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt index 371190a4c4c..8b5900192bb 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt @@ -133,6 +133,7 @@ object FirTreeBuilder : AbstractFirTreeBuilder() { val componentCall by element(Expression, functionCall) val callableReferenceAccess by element(Expression, qualifiedAccessExpression) val thisReceiverExpression by element(Expression, qualifiedAccessExpression) + val inaccessibleReceiverExpression by element(Expression, expression, resolvable) val smartCastExpression by element(Expression, expression) val safeCallExpression by element(Expression, expression) 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 a825bc78335..80cce5f004f 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 @@ -666,7 +666,8 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator() "FirReceiverParameterImpl", "FirClassReferenceExpressionImpl", "FirGetClassCallImpl", - "FirSmartCastExpressionImpl" + "FirSmartCastExpressionImpl", + "FirInaccessibleReceiverExpressionImpl" ) configureFieldInAllImplementations( field = "typeRef", diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt index 21f9a255d03..6f30bcfffe3 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt @@ -727,6 +727,10 @@ object NodeConfigurator : AbstractFieldConfigurator(FirTreeBuild +booleanField("isImplicit") } + inaccessibleReceiverExpression.configure { + +field("calleeReference", thisReference) + } + whenExpression.configure { +field("subject", expression, nullable = true).withTransform() +field("subjectVariable", variable.withArgs("E" to "*"), nullable = true)