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 456fd41ad53..ede1afd9e39 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 @@ -19,7 +19,6 @@ import org.jetbrains.kotlin.fir.resolve.inference.ConeTypeParameterBasedTypeVari import org.jetbrains.kotlin.fir.resolve.inference.ConeTypeVariableForLambdaReturnType import org.jetbrains.kotlin.fir.resolve.inference.model.ConeArgumentConstraintPosition import org.jetbrains.kotlin.fir.resolve.inference.model.ConeExpectedTypeConstraintPosition -import org.jetbrains.kotlin.fir.resolve.inference.model.ConeExplicitTypeParameterConstraintPosition import org.jetbrains.kotlin.fir.resolve.inference.model.ConeLambdaArgumentConstraintPosition import org.jetbrains.kotlin.fir.symbols.impl.FirBackingFieldSymbol import org.jetbrains.kotlin.fir.typeContext @@ -75,7 +74,7 @@ private fun ConeDiagnostic.toFirDiagnostic( FirErrors.NO_TYPE_ARGUMENTS_ON_RHS.createOn(qualifiedAccessSource ?: source, this.desiredCount, this.type) is ConeSimpleDiagnostic -> when (source.kind) { is FirFakeSourceElementKind -> null - else -> this.getFactory(source)?.createOn(qualifiedAccessSource ?: source) + else -> this.getFactory(source).createOn(qualifiedAccessSource ?: source) } is ConeInstanceAccessBeforeSuperCall -> FirErrors.INSTANCE_ACCESS_BEFORE_SUPER_CALL.createOn(source, this.target) is ConeStubDiagnostic -> null @@ -322,7 +321,7 @@ private fun ConstraintSystemError.toDiagnostic( private val NewConstraintError.lowerConeType: ConeKotlinType get() = lowerType as ConeKotlinType private val NewConstraintError.upperConeType: ConeKotlinType get() = upperType as ConeKotlinType -private fun ConeSimpleDiagnostic.getFactory(source: FirSourceElement): FirDiagnosticFactory0? { +private fun ConeSimpleDiagnostic.getFactory(source: FirSourceElement): FirDiagnosticFactory0 { @Suppress("UNCHECKED_CAST") return when (kind) { DiagnosticKind.Syntax -> FirErrors.SYNTAX @@ -365,7 +364,6 @@ private fun ConeSimpleDiagnostic.getFactory(source: FirSourceElement): FirDiagno DiagnosticKind.UnresolvedSupertype, DiagnosticKind.UnresolvedExpandedType, DiagnosticKind.Other -> FirErrors.OTHER_ERROR - DiagnosticKind.NotRootCause -> null else -> throw IllegalArgumentException("Unsupported diagnostic kind: $kind at $javaClass") } } 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 388068addbe..839545ae339 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 @@ -707,8 +707,7 @@ class ExpressionsConverter( whenEntryNodes.mapTo(whenEntries) { convertWhenEntry( it, - subject.takeIf { hasSubject }, - hasSubjectVariable = subjectVariable != null + subject.takeIf { hasSubject } ) } return buildWhenExpression { @@ -756,8 +755,7 @@ class ExpressionsConverter( */ private fun convertWhenEntry( whenEntry: LighterASTNode, - whenRefWithSubject: FirExpressionRef?, - hasSubjectVariable: Boolean + whenRefWithSubject: FirExpressionRef? ): WhenEntry { var isElse = false var firBlock: FirBlock = buildEmptyExpressionBlock() @@ -765,8 +763,8 @@ class ExpressionsConverter( whenEntry.forEachChildren { when (it.tokenType) { WHEN_CONDITION_EXPRESSION -> conditions += convertWhenConditionExpression(it, whenRefWithSubject) - WHEN_CONDITION_IN_RANGE -> conditions += convertWhenConditionInRange(it, whenRefWithSubject, hasSubjectVariable) - WHEN_CONDITION_IS_PATTERN -> conditions += convertWhenConditionIsPattern(it, whenRefWithSubject, hasSubjectVariable) + WHEN_CONDITION_IN_RANGE -> conditions += convertWhenConditionInRange(it, whenRefWithSubject) + WHEN_CONDITION_IS_PATTERN -> conditions += convertWhenConditionIsPattern(it, whenRefWithSubject) ELSE_KEYWORD -> isElse = true BLOCK -> firBlock = declarationsConverter.convertBlock(it) else -> if (it.isExpression()) firBlock = declarationsConverter.convertBlock(it) @@ -809,8 +807,7 @@ class ExpressionsConverter( private fun convertWhenConditionInRange( whenCondition: LighterASTNode, - whenRefWithSubject: FirExpressionRef?, - hasSubjectVariable: Boolean + whenRefWithSubject: FirExpressionRef? ): FirExpression { var isNegate = false var firExpression: FirExpression? = null @@ -838,8 +835,7 @@ class ExpressionsConverter( source = whenCondition.toFirSourceElement() diagnostic = ConeSimpleDiagnostic( "No expression in condition with expression", - // A subject variable without initializer should be highlighted only at the subject expression. - if (hasSubjectVariable) DiagnosticKind.NotRootCause else DiagnosticKind.ExpressionExpected + DiagnosticKind.ExpressionExpected ) } } @@ -859,8 +855,7 @@ class ExpressionsConverter( private fun convertWhenConditionIsPattern( whenCondition: LighterASTNode, - whenRefWithSubject: FirExpressionRef?, - hasSubjectVariable: Boolean + whenRefWithSubject: FirExpressionRef? ): FirExpression { lateinit var firOperation: FirOperation lateinit var firType: FirTypeRef @@ -881,8 +876,7 @@ class ExpressionsConverter( source = whenCondition.toFirSourceElement() diagnostic = ConeSimpleDiagnostic( "No expression in condition with expression", - // A subject variable without initializer should be highlighted only at the subject expression. - if (hasSubjectVariable) DiagnosticKind.NotRootCause else DiagnosticKind.ExpressionExpected + DiagnosticKind.ExpressionExpected ) } } 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 5025690e9f3..e24a9584f56 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 @@ -320,8 +320,7 @@ open class RawFirBuilder( ) } val name = this.getArgumentName()?.asName - val expression = this.getArgumentExpression() - val firExpression = when (expression) { + val firExpression = when (val expression = this.getArgumentExpression()) { is KtConstantExpression, is KtStringTemplateExpression -> { expression.accept(this@Visitor, Unit) as FirExpression } @@ -580,7 +579,7 @@ open class RawFirBuilder( container.argumentList = argumentList } - fun KtClassOrObject.extractSuperTypeListEntriesTo( + private fun KtClassOrObject.extractSuperTypeListEntriesTo( container: FirClassBuilder, delegatedSelfTypeRef: FirTypeRef?, delegatedEnumSuperTypeRef: FirTypeRef?, @@ -1754,9 +1753,7 @@ open class RawFirBuilder( ?: ktCondition) .toFirExpression( "No expression in condition with expression", - // A subject variable without initializer should be highlighted only at the subject expression. - if (ktSubjectExpression is KtVariableDeclaration) DiagnosticKind.NotRootCause - else DiagnosticKind.ExpressionExpected + DiagnosticKind.ExpressionExpected ) result = branchBody } 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 8b400d19419..979a7486183 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 @@ -52,10 +52,4 @@ enum class DiagnosticKind { WrongLongSuffix, Other, - - /** - * Special diagnostic kind that is caused by issues at other places in the code. Such diagnostics should not be reported so that user - * sees less noise. - */ - NotRootCause } diff --git a/compiler/testData/diagnostics/tests/when/withSubjectVariable/unsupportedVariableDeclarationsInWhenSubject.fir.kt b/compiler/testData/diagnostics/tests/when/withSubjectVariable/unsupportedVariableDeclarationsInWhenSubject.fir.kt index 514c5237438..803b4e0922c 100644 --- a/compiler/testData/diagnostics/tests/when/withSubjectVariable/unsupportedVariableDeclarationsInWhenSubject.fir.kt +++ b/compiler/testData/diagnostics/tests/when/withSubjectVariable/unsupportedVariableDeclarationsInWhenSubject.fir.kt @@ -12,7 +12,7 @@ fun testSimpleValInWhenSubject() { fun testValWithoutInitializerWhenSubject() { when (val y: Any) { - is String -> y.length + is String -> y.length } }