diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDestructuringDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDestructuringDeclarationChecker.kt index 5e41b0ee3d3..90def843488 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDestructuringDeclarationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDestructuringDeclarationChecker.kt @@ -16,11 +16,8 @@ import org.jetbrains.kotlin.fir.declarations.FirResolvePhase import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.declarations.FirVariable import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic -import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic -import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind +import org.jetbrains.kotlin.fir.diagnostics.ConeSyntaxDiagnostic import org.jetbrains.kotlin.fir.expressions.* -import org.jetbrains.kotlin.fir.references.FirErrorNamedReference -import org.jetbrains.kotlin.fir.references.FirResolvedErrorReference import org.jetbrains.kotlin.fir.references.isError import org.jetbrains.kotlin.fir.references.toResolvedVariableSymbol import org.jetbrains.kotlin.fir.resolve.diagnostics.* @@ -97,7 +94,7 @@ object FirDestructuringDeclarationChecker : FirPropertyChecker() { val needToReport = when (initializer) { null -> true - is FirErrorExpression -> (initializer.diagnostic as? ConeSimpleDiagnostic)?.kind == DiagnosticKind.Syntax + is FirErrorExpression -> initializer.diagnostic is ConeSyntaxDiagnostic else -> false } if (needToReport) { 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 5d9733b07a1..ecb85e64fbb 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 @@ -100,9 +100,10 @@ private fun ConeDiagnostic.toKtDiagnostic( is ConeNoTypeArgumentsOnRhsError -> FirErrors.NO_TYPE_ARGUMENTS_ON_RHS.createOn(qualifiedAccessSource ?: source, this.desiredCount, this.symbol) + is ConeSyntaxDiagnostic -> FirSyntaxErrors.SYNTAX.createOn(qualifiedAccessSource ?: source, reason) + is ConeSimpleDiagnostic -> when { source.kind is KtFakeSourceElementKind && source.kind != KtFakeSourceElementKind.ReferenceInAtomicQualifiedAccess -> null - kind == DiagnosticKind.Syntax -> FirSyntaxErrors.SYNTAX.createOn(qualifiedAccessSource ?: source, reason) else -> this.getFactory(source).createOn(qualifiedAccessSource ?: source) } @@ -534,7 +535,6 @@ private fun ConeSimpleDiagnostic.getFactory(source: KtSourceElement): KtDiagnost DiagnosticKind.UnresolvedSupertype, DiagnosticKind.UnresolvedExpandedType, DiagnosticKind.Other -> FirErrors.OTHER_ERROR - DiagnosticKind.Syntax -> error("Must not be called on `Syntax` because a message is required.") } } diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt index c089f8f1f59..ae52f8d5042 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt @@ -29,10 +29,7 @@ import org.jetbrains.kotlin.fir.declarations.utils.DanglingTypeConstraint import org.jetbrains.kotlin.fir.declarations.utils.addDeclarations import org.jetbrains.kotlin.fir.declarations.utils.addDefaultBoundIfNecessary import org.jetbrains.kotlin.fir.declarations.utils.danglingTypeConstraints -import org.jetbrains.kotlin.fir.diagnostics.ConeDanglingModifierOnTopLevel -import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic -import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic -import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind +import org.jetbrains.kotlin.fir.diagnostics.* import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.builder.* import org.jetbrains.kotlin.fir.expressions.impl.FirSingleExpressionBlock @@ -47,10 +44,13 @@ import org.jetbrains.kotlin.fir.references.builder.buildSimpleNamedReference import org.jetbrains.kotlin.fir.scopes.FirScopeProvider import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.* -import org.jetbrains.kotlin.fir.types.* +import org.jetbrains.kotlin.fir.types.ConeClassLikeType +import org.jetbrains.kotlin.fir.types.FirTypeProjection +import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.types.FirUserTypeRef import org.jetbrains.kotlin.fir.types.builder.* -import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImplWithoutSource import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl +import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImplWithoutSource import org.jetbrains.kotlin.fir.types.impl.FirQualifierPartImpl import org.jetbrains.kotlin.fir.types.impl.FirTypeArgumentListImpl import org.jetbrains.kotlin.lexer.KtModifierKeywordToken @@ -1329,7 +1329,7 @@ class DeclarationsConverter( entries, firExpression ?: buildErrorExpression( null, - ConeSimpleDiagnostic("Initializer required for destructuring declaration", DiagnosticKind.Syntax) + ConeSyntaxDiagnostic("Initializer required for destructuring declaration") ), source, modifiers @@ -1875,7 +1875,7 @@ class DeclarationsConverter( } val calculatedFirExpression = firExpression ?: buildErrorExpression( - explicitDelegation.toFirSourceElement(), ConeSimpleDiagnostic("Should have delegate", DiagnosticKind.Syntax) + explicitDelegation.toFirSourceElement(), ConeSyntaxDiagnostic("Should have delegate") ) delegateFieldsMap.put( @@ -2028,14 +2028,14 @@ class DeclarationsConverter( CONTEXT_RECEIVER_LIST, TokenType.ERROR_ELEMENT -> firType = buildErrorTypeRef { source = typeRefSource - diagnostic = ConeSimpleDiagnostic("Unwrapped type is null", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("Unwrapped type is null") } } } val calculatedFirType = firType ?: buildErrorTypeRef { source = typeRefSource - diagnostic = ConeSimpleDiagnostic("Incomplete code", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("Incomplete code") } for (modifierList in allTypeModifiers) { @@ -2057,7 +2057,7 @@ class DeclarationsConverter( if (children.size != 2) { return buildErrorTypeRef { source = typeRefSource - diagnostic = ConeSimpleDiagnostic("Wrong code", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("Wrong code") } } @@ -2140,7 +2140,7 @@ class DeclarationsConverter( if (identifier == null) return buildErrorTypeRef { source = typeRefSource - diagnostic = ConeSimpleDiagnostic("Incomplete user type", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("Incomplete user type") } val qualifierPart = FirQualifierPartImpl( diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt index ece6946935f..0c106ecad47 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt @@ -33,7 +33,6 @@ import org.jetbrains.kotlin.fir.expressions.builder.* import org.jetbrains.kotlin.fir.expressions.impl.FirContractCallBlock import org.jetbrains.kotlin.fir.expressions.impl.FirSingleExpressionBlock import org.jetbrains.kotlin.fir.expressions.impl.buildSingleExpressionBlock -import org.jetbrains.kotlin.fir.lightTree.LightTree2Fir import org.jetbrains.kotlin.fir.lightTree.fir.ValueParameter import org.jetbrains.kotlin.fir.lightTree.fir.WhenEntry import org.jetbrains.kotlin.fir.references.FirNamedReference @@ -210,7 +209,7 @@ class ExpressionsConverter( statements.addAll(0, destructuringStatements) }.build() } else { - buildSingleExpressionBlock(buildErrorExpression(null, ConeSimpleDiagnostic("Lambda has no body", DiagnosticKind.Syntax))) + buildSingleExpressionBlock(buildErrorExpression(null, ConeSyntaxDiagnostic("Lambda has no body"))) } context.firFunctionTargets.removeLast() }.also { @@ -261,7 +260,7 @@ class ExpressionsConverter( if (rightArg != null) getAsFirExpression(rightArg, "No right operand") else - buildErrorExpression(null, ConeSimpleDiagnostic("No right operand", DiagnosticKind.Syntax)) + buildErrorExpression(null, ConeSyntaxDiagnostic("No right operand")) val leftArgAsFir = getAsFirExpression(leftArgNode, "No left operand") @@ -336,7 +335,7 @@ class ExpressionsConverter( operation = operationTokenName.toFirOperation() conversionTypeRef = firType argumentList = buildUnaryArgumentList( - leftArgAsFir ?: buildErrorExpression(null, ConeSimpleDiagnostic("No left operand", DiagnosticKind.Syntax)) + leftArgAsFir ?: buildErrorExpression(null, ConeSyntaxDiagnostic("No left operand")) ) } } @@ -466,7 +465,7 @@ class ExpressionsConverter( source = classLiteralExpression.toFirSourceElement() argumentList = buildUnaryArgumentList( firReceiverExpression - ?: buildErrorExpression(null, ConeSimpleDiagnostic("No receiver in class literal", DiagnosticKind.Syntax)) + ?: buildErrorExpression(null, ConeSyntaxDiagnostic("No receiver in class literal")) ) } } @@ -567,14 +566,14 @@ class ExpressionsConverter( this.receiver = receiver this.selector = errorExpression source = dotQualifiedExpression.toFirSourceElement() - diagnostic = ConeSimpleDiagnostic("Qualified expression with unexpected selector", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("Qualified expression with unexpected selector") } } } return result ?: buildErrorExpression { source = null - diagnostic = ConeSimpleDiagnostic("Qualified expression without selector", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("Qualified expression without selector") // if there is no selector, we still want to resolve the receiver expression = firReceiver @@ -653,7 +652,7 @@ class ExpressionsConverter( else -> CalleeAndReceiver( buildErrorNamedReference { this.source = source - diagnostic = ConeSimpleDiagnostic("Call has no callee", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("Call has no callee") } ) } @@ -692,7 +691,7 @@ class ExpressionsConverter( this?.forEachChildren(LONG_TEMPLATE_ENTRY_START, LONG_TEMPLATE_ENTRY_END) { firExpression = getAsFirExpression(it, errorReason) } - return firExpression ?: buildErrorExpression(null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.Syntax)) + return firExpression ?: buildErrorExpression(null, ConeSyntaxDiagnostic(errorReason)) } /** @@ -822,7 +821,7 @@ class ExpressionsConverter( val calculatedFirExpression = firExpression ?: buildErrorExpression( source = null, - ConeSimpleDiagnostic("No expression in condition with expression", DiagnosticKind.Syntax) + ConeSyntaxDiagnostic("No expression in condition with expression") ) if (whenRefWithSubject == null) { @@ -879,7 +878,7 @@ class ExpressionsConverter( val calculatedFirExpression = firExpression ?: buildErrorExpression( null, - ConeSimpleDiagnostic("No range in condition with range", DiagnosticKind.Syntax) + ConeSyntaxDiagnostic("No range in condition with range") ) return calculatedFirExpression.generateContainsOperation( @@ -949,7 +948,7 @@ class ExpressionsConverter( name = if (isGet) OperatorNameConventions.GET else OperatorNameConventions.SET } explicitReceiver = - firExpression ?: buildErrorExpression(null, ConeSimpleDiagnostic("No array expression", DiagnosticKind.Syntax)) + firExpression ?: buildErrorExpression(null, ConeSyntaxDiagnostic("No array expression")) argumentList = buildArgumentList { arguments += indices getArgument?.let { arguments += it } @@ -1038,7 +1037,7 @@ class ExpressionsConverter( } } condition = - firCondition ?: buildErrorExpression(null, ConeSimpleDiagnostic("No condition in do-while loop", DiagnosticKind.Syntax)) + firCondition ?: buildErrorExpression(null, ConeSyntaxDiagnostic("No condition in do-while loop")) }.configure(target) { convertLoopBody(block) } } @@ -1060,7 +1059,7 @@ class ExpressionsConverter( return FirWhileLoopBuilder().apply { source = whileLoop.toFirSourceElement() condition = - firCondition ?: buildErrorExpression(null, ConeSimpleDiagnostic("No condition in while loop", DiagnosticKind.Syntax)) + firCondition ?: buildErrorExpression(null, ConeSyntaxDiagnostic("No condition in while loop")) // break/continue in the while loop condition will refer to an outer loop if any. // So, prepare the loop target after building the condition. target = prepareTarget(whileLoop) @@ -1084,7 +1083,7 @@ class ExpressionsConverter( } val calculatedRangeExpression = - rangeExpression ?: buildErrorExpression(null, ConeSimpleDiagnostic("No range in for loop", DiagnosticKind.Syntax)) + rangeExpression ?: buildErrorExpression(null, ConeSyntaxDiagnostic("No range in for loop")) val fakeSource = forLoop.toFirSourceElement(KtFakeSourceElementKind.DesugaredForLoop) val target: FirLoopTarget // NB: FirForLoopChecker relies on this block existence and structure @@ -1271,7 +1270,7 @@ class ExpressionsConverter( source = thenBlock?.toFirSourceElement() condition = firCondition ?: buildErrorExpression( null, - ConeSimpleDiagnostic("If statement should have condition", DiagnosticKind.Syntax) + ConeSyntaxDiagnostic("If statement should have condition") ) result = trueBranch } @@ -1393,7 +1392,7 @@ class ExpressionsConverter( return buildThrowExpression { source = throwExpression.toFirSourceElement() - exception = firExpression ?: buildErrorExpression(null, ConeSimpleDiagnostic("Nothing to throw", DiagnosticKind.Syntax)) + exception = firExpression ?: buildErrorExpression(null, ConeSyntaxDiagnostic("Nothing to throw")) } } @@ -1466,7 +1465,7 @@ class ExpressionsConverter( } } val calculatedFirExpression = - firExpression ?: buildErrorExpression(null, ConeSimpleDiagnostic("Argument is absent", DiagnosticKind.Syntax)) + firExpression ?: buildErrorExpression(null, ConeSyntaxDiagnostic("Argument is absent")) return when { identifier != null -> buildNamedArgumentExpression { source = valueArgument.toFirSourceElement() diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt index 4bd1a8cb210..aa1b51cdaa8 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt @@ -28,8 +28,7 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter import org.jetbrains.kotlin.fir.declarations.utils.fromPrimaryConstructor import org.jetbrains.kotlin.fir.declarations.utils.isFromVararg -import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic -import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind +import org.jetbrains.kotlin.fir.diagnostics.ConeSyntaxDiagnostic import org.jetbrains.kotlin.fir.expressions.FirAnnotation import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.builder.buildPropertyAccessExpression @@ -106,7 +105,7 @@ class ValueParameter( val name = this.firValueParameter.name var type = this.firValueParameter.returnTypeRef if (type is FirImplicitTypeRef) { - type = buildErrorTypeRef { diagnostic = ConeSimpleDiagnostic("Incomplete code", DiagnosticKind.Syntax) } + type = buildErrorTypeRef { diagnostic = ConeSyntaxDiagnostic("Incomplete code") } } return buildProperty { diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/WhenEntry.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/WhenEntry.kt index a1c194c6d7e..3261ea92e77 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/WhenEntry.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/WhenEntry.kt @@ -7,8 +7,7 @@ package org.jetbrains.kotlin.fir.lightTree.fir import com.intellij.lang.LighterASTNode import org.jetbrains.kotlin.fir.builder.buildBalancedOrExpressionTree -import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind -import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic +import org.jetbrains.kotlin.fir.diagnostics.ConeSyntaxDiagnostic import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.buildErrorExpression @@ -26,7 +25,7 @@ data class WhenEntry( fun toFirWhenConditionWithoutSubject(): FirExpression { return when (val condition = conditions.firstOrNull()) { - null -> buildErrorExpression(null, ConeSimpleDiagnostic("No expression in condition with expression", DiagnosticKind.Syntax)) + null -> buildErrorExpression(null, ConeSyntaxDiagnostic("No expression in condition with expression")) else -> condition } } diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiConversionUtils.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiConversionUtils.kt index 3c05ac4e327..740e0c34927 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiConversionUtils.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiConversionUtils.kt @@ -14,8 +14,7 @@ import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin import org.jetbrains.kotlin.fir.declarations.FirVariable import org.jetbrains.kotlin.fir.declarations.builder.buildProperty import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl -import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic -import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind +import org.jetbrains.kotlin.fir.diagnostics.ConeSyntaxDiagnostic import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.builder.* import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol @@ -62,7 +61,7 @@ internal fun KtWhenCondition.toFirWhenCondition( } } else -> { - buildErrorExpression(firSubjectSource, ConeSimpleDiagnostic("Unsupported when condition: ${this.javaClass}", DiagnosticKind.Syntax)) + buildErrorExpression(firSubjectSource, ConeSyntaxDiagnostic("Unsupported when condition: ${this.javaClass}")) } } } diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index f70694409c9..a67a949ac66 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -253,8 +253,8 @@ open class RawFirBuilder( private fun KtTypeReference?.toFirOrErrorType(): FirTypeRef = convertSafe() ?: buildErrorTypeRef { source = this@toFirOrErrorType?.toFirSourceElement() - diagnostic = ConeSimpleDiagnostic( - if (this@toFirOrErrorType == null) "Incomplete code" else "Conversion failed", DiagnosticKind.Syntax + diagnostic = ConeSyntaxDiagnostic( + if (this@toFirOrErrorType == null) "Incomplete code" else "Conversion failed" ) } @@ -265,9 +265,11 @@ open class RawFirBuilder( private fun KtElement?.toFirExpression( errorReason: String, kind: DiagnosticKind = DiagnosticKind.ExpressionExpected - ): FirExpression { + ): FirExpression = toFirExpression { ConeSimpleDiagnostic(errorReason, kind) } + + private inline fun KtElement?.toFirExpression(diagnosticFn: () -> ConeDiagnostic): FirExpression { if (this == null) { - return buildErrorExpression(source = null, ConeSimpleDiagnostic(errorReason, kind)) + return buildErrorExpression(source = null, diagnosticFn()) } val result = when (val fir = convertElement(this)) { @@ -275,13 +277,16 @@ open class RawFirBuilder( else -> { return buildErrorExpression { nonExpressionElement = fir - diagnostic = ConeSimpleDiagnostic(errorReason, kind) + diagnostic = diagnosticFn() source = toFirSourceElement() } } } + return toFirExpression(result) + } + private fun KtElement.toFirExpression(result: FirExpression): FirExpression { val callExpressionCallee = (this as? KtCallExpression)?.calleeExpression?.unwrapParenthesesLabelsAndAnnotations() if (this is KtNameReferenceExpression || @@ -307,7 +312,7 @@ open class RawFirBuilder( is FirStatement -> fir else -> buildErrorExpression { nonExpressionElement = fir - diagnostic = ConeSimpleDiagnostic(errorReasonLazy(), DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic(errorReasonLazy()) source = toFirSourceElement() } } @@ -393,7 +398,7 @@ open class RawFirBuilder( if (this == null) { return buildErrorExpression( source = null, - ConeSimpleDiagnostic("No argument given", DiagnosticKind.Syntax), + ConeSyntaxDiagnostic("No argument given"), ) } val name = this.getArgumentName()?.asName @@ -1614,7 +1619,7 @@ open class RawFirBuilder( } val ktBody = literal.bodyExpression body = if (ktBody == null) { - val errorExpression = buildErrorExpression(source, ConeSimpleDiagnostic("Lambda has no body", DiagnosticKind.Syntax)) + val errorExpression = buildErrorExpression(source, ConeSyntaxDiagnostic("Lambda has no body")) FirSingleExpressionBlock(errorExpression.toReturn()) } else { configureBlockWithoutBuilding(ktBody).apply { @@ -1959,7 +1964,7 @@ open class RawFirBuilder( } else { FirErrorTypeRefBuilder().apply { this.source = source - diagnostic = ConeSimpleDiagnostic("Incomplete user type", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("Incomplete user type") } } } @@ -1997,7 +2002,7 @@ open class RawFirBuilder( } null -> FirErrorTypeRefBuilder().apply { this.source = source - diagnostic = ConeSimpleDiagnostic("Incomplete code", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("Incomplete code") } else -> throw AssertionError("Unexpected type element: ${unwrappedElement.text}") } @@ -2538,7 +2543,7 @@ open class RawFirBuilder( null -> { CalleeAndReceiver( - buildErrorNamedReference { diagnostic = ConeSimpleDiagnostic("Call has no callee", DiagnosticKind.Syntax) } + buildErrorNamedReference { diagnostic = ConeSyntaxDiagnostic("Call has no callee") } ) } @@ -2620,7 +2625,7 @@ open class RawFirBuilder( val selector = expression.selectorExpression ?: return buildErrorExpression { source = expression.toFirSourceElement() - diagnostic = ConeSimpleDiagnostic("Qualified expression without selector", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("Qualified expression without selector") // if there is no selector, we still want to resolve the receiver this.expression = receiver @@ -2644,7 +2649,7 @@ open class RawFirBuilder( this.receiver = receiver this.selector = firSelector source = expression.toFirSourceElement() - diagnostic = ConeSimpleDiagnostic("Qualified expression with unexpected selector", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("Qualified expression with unexpected selector") } } return firSelector @@ -2679,7 +2684,7 @@ open class RawFirBuilder( return expression.expression?.accept(this, data) ?: buildErrorExpression( expression.toFirSourceElement(), - ConeSimpleDiagnostic("Empty parentheses", DiagnosticKind.Syntax) + ConeSyntaxDiagnostic("Empty parentheses") ) } @@ -2726,10 +2731,7 @@ open class RawFirBuilder( baseModuleData, multiDeclaration.toFirSourceElement(), "destruct", - multiDeclaration.initializer.toFirExpression( - "Initializer required for destructuring declaration", - DiagnosticKind.Syntax - ), + multiDeclaration.initializer.toFirExpression { ConeSyntaxDiagnostic("Initializer required for destructuring declaration") }, extractAnnotationsTo = { extractAnnotationsTo(it) } ) return generateDestructuringBlock( diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt index 378641dc354..2bfe343d3ce 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt @@ -22,7 +22,9 @@ import org.jetbrains.kotlin.fir.declarations.utils.isLocal import org.jetbrains.kotlin.fir.diagnostics.* import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.builder.* -import org.jetbrains.kotlin.fir.references.builder.* +import org.jetbrains.kotlin.fir.references.builder.buildImplicitThisReference +import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference +import org.jetbrains.kotlin.fir.references.builder.buildSimpleNamedReference import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.ConeClassLikeType import org.jetbrains.kotlin.fir.types.FirErrorTypeRef @@ -460,7 +462,7 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte hasExpressions = true buildErrorExpression { source = entry.toFirSourceElement() - diagnostic = ConeSimpleDiagnostic("Incorrect template entry: ${entry.asText}", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("Incorrect template entry: ${entry.asText}") } } } @@ -482,7 +484,7 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte convert: T.() -> FirExpression ): FirExpression { val unwrappedReceiver = receiver.unwrap() ?: return buildErrorExpression { - diagnostic = ConeSimpleDiagnostic("Inc/dec without operand", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("Inc/dec without operand") } if (unwrappedReceiver.elementType == ARRAY_ACCESS_EXPRESSION) { @@ -668,7 +670,7 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte ): FirExpression { val receiverFir = receiver?.convert() ?: buildErrorExpression { source = sourceElementForError - diagnostic = ConeSimpleDiagnostic("No receiver expression", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("No receiver expression") } if (receiverFir is FirSafeCallExpression) { @@ -677,7 +679,7 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte init( receiverFir.selector as? FirExpression ?: buildErrorExpression { source = sourceElementForError - diagnostic = ConeSimpleDiagnostic("Safe call selector expected to be an expression here", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("Safe call selector expected to be an expression here") } ) } @@ -706,7 +708,7 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte convert: T.() -> FirExpression ): FirStatement { val unwrappedLhs = this.unwrap() ?: return buildErrorExpression { - diagnostic = ConeSimpleDiagnostic("Inc/dec without operand", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("Inc/dec without operand") } val tokenType = unwrappedLhs.elementType @@ -830,7 +832,7 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte this.lhsGetCall = receiver this.rhs = rhs?.convert() ?: buildErrorExpression( null, - ConeSimpleDiagnostic("No value for array set", DiagnosticKind.Syntax) + ConeSyntaxDiagnostic("No value for array set") ) this.arrayAccessSource = arrayAccessSource this.annotations += annotations @@ -944,7 +946,7 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte element } } else { - buildErrorExpression(elementSource, ConeSimpleDiagnostic("Empty label", DiagnosticKind.Syntax)) + buildErrorExpression(elementSource, ConeSyntaxDiagnostic("Empty label")) } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt index 0cea7c6ad59..033dee018ef 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt @@ -22,7 +22,9 @@ import org.jetbrains.kotlin.fir.extensions.assignAltererExtensions import org.jetbrains.kotlin.fir.extensions.expressionResolutionExtensions import org.jetbrains.kotlin.fir.extensions.extensionService import org.jetbrains.kotlin.fir.references.* -import org.jetbrains.kotlin.fir.references.builder.* +import org.jetbrains.kotlin.fir.references.builder.buildErrorNamedReference +import org.jetbrains.kotlin.fir.references.builder.buildExplicitSuperReference +import org.jetbrains.kotlin.fir.references.builder.buildSimpleNamedReference import org.jetbrains.kotlin.fir.references.impl.FirSimpleNamedReference import org.jetbrains.kotlin.fir.resolve.* import org.jetbrains.kotlin.fir.resolve.calls.* @@ -701,7 +703,7 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT val expression = when (originalExpression) { is FirSafeCallExpression -> originalExpression.selector as? FirExpression ?: buildErrorExpression { source = originalExpression.source - diagnostic = ConeSimpleDiagnostic("Safe call selector expected to be an expression here", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("Safe call selector expected to be an expression here") } else -> originalExpression } @@ -1519,7 +1521,7 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT initializer = lhsGetCall.explicitReceiver ?: buildErrorExpression { source = augmentedArraySetCall.source ?.fakeElement(KtFakeSourceElementKind.DesugaredCompoundAssignment) - diagnostic = ConeSimpleDiagnostic("No receiver for array access", DiagnosticKind.Syntax) + diagnostic = ConeSyntaxDiagnostic("No receiver for array access") } ) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt index 45423ea105b..239aae077e3 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt @@ -15,6 +15,8 @@ import org.jetbrains.kotlin.name.Name class ConeSimpleDiagnostic(override val reason: String, val kind: DiagnosticKind = DiagnosticKind.Other) : ConeDiagnostic +class ConeSyntaxDiagnostic(override val reason: String) : ConeDiagnostic + class ConeNotAnnotationContainer(val text: String) : ConeDiagnostic { override val reason: String get() = "Strange annotated expression: $text" } @@ -70,7 +72,6 @@ class ConeAmbiguousFunctionTypeKinds(val kinds: List) : ConeDi } enum class DiagnosticKind { - Syntax, ExpressionExpected, NotLoopLabel, JumpOutsideLoop,