FIR: drop questionable DiagnosticKind.NotRootCause

This commit is contained in:
Mikhail Glukhikh
2021-07-06 10:44:11 +03:00
parent 7d583973ab
commit bf40c07cc3
5 changed files with 14 additions and 31 deletions
@@ -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.ConeTypeVariableForLambdaReturnType
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeArgumentConstraintPosition 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.ConeExpectedTypeConstraintPosition
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeExplicitTypeParameterConstraintPosition
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeLambdaArgumentConstraintPosition import org.jetbrains.kotlin.fir.resolve.inference.model.ConeLambdaArgumentConstraintPosition
import org.jetbrains.kotlin.fir.symbols.impl.FirBackingFieldSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirBackingFieldSymbol
import org.jetbrains.kotlin.fir.typeContext 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) FirErrors.NO_TYPE_ARGUMENTS_ON_RHS.createOn(qualifiedAccessSource ?: source, this.desiredCount, this.type)
is ConeSimpleDiagnostic -> when (source.kind) { is ConeSimpleDiagnostic -> when (source.kind) {
is FirFakeSourceElementKind -> null 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 ConeInstanceAccessBeforeSuperCall -> FirErrors.INSTANCE_ACCESS_BEFORE_SUPER_CALL.createOn(source, this.target)
is ConeStubDiagnostic -> null is ConeStubDiagnostic -> null
@@ -322,7 +321,7 @@ private fun ConstraintSystemError.toDiagnostic(
private val NewConstraintError.lowerConeType: ConeKotlinType get() = lowerType as ConeKotlinType private val NewConstraintError.lowerConeType: ConeKotlinType get() = lowerType as ConeKotlinType
private val NewConstraintError.upperConeType: ConeKotlinType get() = upperType 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") @Suppress("UNCHECKED_CAST")
return when (kind) { return when (kind) {
DiagnosticKind.Syntax -> FirErrors.SYNTAX DiagnosticKind.Syntax -> FirErrors.SYNTAX
@@ -365,7 +364,6 @@ private fun ConeSimpleDiagnostic.getFactory(source: FirSourceElement): FirDiagno
DiagnosticKind.UnresolvedSupertype, DiagnosticKind.UnresolvedSupertype,
DiagnosticKind.UnresolvedExpandedType, DiagnosticKind.UnresolvedExpandedType,
DiagnosticKind.Other -> FirErrors.OTHER_ERROR DiagnosticKind.Other -> FirErrors.OTHER_ERROR
DiagnosticKind.NotRootCause -> null
else -> throw IllegalArgumentException("Unsupported diagnostic kind: $kind at $javaClass") else -> throw IllegalArgumentException("Unsupported diagnostic kind: $kind at $javaClass")
} }
} }
@@ -707,8 +707,7 @@ class ExpressionsConverter(
whenEntryNodes.mapTo(whenEntries) { whenEntryNodes.mapTo(whenEntries) {
convertWhenEntry( convertWhenEntry(
it, it,
subject.takeIf { hasSubject }, subject.takeIf { hasSubject }
hasSubjectVariable = subjectVariable != null
) )
} }
return buildWhenExpression { return buildWhenExpression {
@@ -756,8 +755,7 @@ class ExpressionsConverter(
*/ */
private fun convertWhenEntry( private fun convertWhenEntry(
whenEntry: LighterASTNode, whenEntry: LighterASTNode,
whenRefWithSubject: FirExpressionRef<FirWhenExpression>?, whenRefWithSubject: FirExpressionRef<FirWhenExpression>?
hasSubjectVariable: Boolean
): WhenEntry { ): WhenEntry {
var isElse = false var isElse = false
var firBlock: FirBlock = buildEmptyExpressionBlock() var firBlock: FirBlock = buildEmptyExpressionBlock()
@@ -765,8 +763,8 @@ class ExpressionsConverter(
whenEntry.forEachChildren { whenEntry.forEachChildren {
when (it.tokenType) { when (it.tokenType) {
WHEN_CONDITION_EXPRESSION -> conditions += convertWhenConditionExpression(it, whenRefWithSubject) WHEN_CONDITION_EXPRESSION -> conditions += convertWhenConditionExpression(it, whenRefWithSubject)
WHEN_CONDITION_IN_RANGE -> conditions += convertWhenConditionInRange(it, whenRefWithSubject, hasSubjectVariable) WHEN_CONDITION_IN_RANGE -> conditions += convertWhenConditionInRange(it, whenRefWithSubject)
WHEN_CONDITION_IS_PATTERN -> conditions += convertWhenConditionIsPattern(it, whenRefWithSubject, hasSubjectVariable) WHEN_CONDITION_IS_PATTERN -> conditions += convertWhenConditionIsPattern(it, whenRefWithSubject)
ELSE_KEYWORD -> isElse = true ELSE_KEYWORD -> isElse = true
BLOCK -> firBlock = declarationsConverter.convertBlock(it) BLOCK -> firBlock = declarationsConverter.convertBlock(it)
else -> if (it.isExpression()) firBlock = declarationsConverter.convertBlock(it) else -> if (it.isExpression()) firBlock = declarationsConverter.convertBlock(it)
@@ -809,8 +807,7 @@ class ExpressionsConverter(
private fun convertWhenConditionInRange( private fun convertWhenConditionInRange(
whenCondition: LighterASTNode, whenCondition: LighterASTNode,
whenRefWithSubject: FirExpressionRef<FirWhenExpression>?, whenRefWithSubject: FirExpressionRef<FirWhenExpression>?
hasSubjectVariable: Boolean
): FirExpression { ): FirExpression {
var isNegate = false var isNegate = false
var firExpression: FirExpression? = null var firExpression: FirExpression? = null
@@ -838,8 +835,7 @@ class ExpressionsConverter(
source = whenCondition.toFirSourceElement() source = whenCondition.toFirSourceElement()
diagnostic = ConeSimpleDiagnostic( diagnostic = ConeSimpleDiagnostic(
"No expression in condition with expression", "No expression in condition with expression",
// A subject variable without initializer should be highlighted only at the subject expression. DiagnosticKind.ExpressionExpected
if (hasSubjectVariable) DiagnosticKind.NotRootCause else DiagnosticKind.ExpressionExpected
) )
} }
} }
@@ -859,8 +855,7 @@ class ExpressionsConverter(
private fun convertWhenConditionIsPattern( private fun convertWhenConditionIsPattern(
whenCondition: LighterASTNode, whenCondition: LighterASTNode,
whenRefWithSubject: FirExpressionRef<FirWhenExpression>?, whenRefWithSubject: FirExpressionRef<FirWhenExpression>?
hasSubjectVariable: Boolean
): FirExpression { ): FirExpression {
lateinit var firOperation: FirOperation lateinit var firOperation: FirOperation
lateinit var firType: FirTypeRef lateinit var firType: FirTypeRef
@@ -881,8 +876,7 @@ class ExpressionsConverter(
source = whenCondition.toFirSourceElement() source = whenCondition.toFirSourceElement()
diagnostic = ConeSimpleDiagnostic( diagnostic = ConeSimpleDiagnostic(
"No expression in condition with expression", "No expression in condition with expression",
// A subject variable without initializer should be highlighted only at the subject expression. DiagnosticKind.ExpressionExpected
if (hasSubjectVariable) DiagnosticKind.NotRootCause else DiagnosticKind.ExpressionExpected
) )
} }
} }
@@ -320,8 +320,7 @@ open class RawFirBuilder(
) )
} }
val name = this.getArgumentName()?.asName val name = this.getArgumentName()?.asName
val expression = this.getArgumentExpression() val firExpression = when (val expression = this.getArgumentExpression()) {
val firExpression = when (expression) {
is KtConstantExpression, is KtStringTemplateExpression -> { is KtConstantExpression, is KtStringTemplateExpression -> {
expression.accept(this@Visitor, Unit) as FirExpression expression.accept(this@Visitor, Unit) as FirExpression
} }
@@ -580,7 +579,7 @@ open class RawFirBuilder(
container.argumentList = argumentList container.argumentList = argumentList
} }
fun KtClassOrObject.extractSuperTypeListEntriesTo( private fun KtClassOrObject.extractSuperTypeListEntriesTo(
container: FirClassBuilder, container: FirClassBuilder,
delegatedSelfTypeRef: FirTypeRef?, delegatedSelfTypeRef: FirTypeRef?,
delegatedEnumSuperTypeRef: FirTypeRef?, delegatedEnumSuperTypeRef: FirTypeRef?,
@@ -1754,9 +1753,7 @@ open class RawFirBuilder(
?: ktCondition) ?: ktCondition)
.toFirExpression( .toFirExpression(
"No expression in condition with expression", "No expression in condition with expression",
// A subject variable without initializer should be highlighted only at the subject expression. DiagnosticKind.ExpressionExpected
if (ktSubjectExpression is KtVariableDeclaration) DiagnosticKind.NotRootCause
else DiagnosticKind.ExpressionExpected
) )
result = branchBody result = branchBody
} }
@@ -52,10 +52,4 @@ enum class DiagnosticKind {
WrongLongSuffix, WrongLongSuffix,
Other, 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
} }
@@ -12,7 +12,7 @@ fun testSimpleValInWhenSubject() {
fun testValWithoutInitializerWhenSubject() { fun testValWithoutInitializerWhenSubject() {
when (<!ILLEGAL_DECLARATION_IN_WHEN_SUBJECT!>val y: Any<!>) { when (<!ILLEGAL_DECLARATION_IN_WHEN_SUBJECT!>val y: Any<!>) {
is String -> <!UNINITIALIZED_VARIABLE!>y<!>.<!UNRESOLVED_REFERENCE!>length<!> <!EXPECTED_CONDITION!>is String<!> -> <!UNINITIALIZED_VARIABLE!>y<!>.<!UNRESOLVED_REFERENCE!>length<!>
} }
} }