FIR: drop questionable DiagnosticKind.NotRootCause
This commit is contained in:
+2
-4
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
+8
-14
@@ -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<FirWhenExpression>?,
|
||||
hasSubjectVariable: Boolean
|
||||
whenRefWithSubject: FirExpressionRef<FirWhenExpression>?
|
||||
): 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<FirWhenExpression>?,
|
||||
hasSubjectVariable: Boolean
|
||||
whenRefWithSubject: FirExpressionRef<FirWhenExpression>?
|
||||
): 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<FirWhenExpression>?,
|
||||
hasSubjectVariable: Boolean
|
||||
whenRefWithSubject: FirExpressionRef<FirWhenExpression>?
|
||||
): 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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ fun testSimpleValInWhenSubject() {
|
||||
|
||||
fun testValWithoutInitializerWhenSubject() {
|
||||
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<!>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user