[FIR] Prohibit using FirDiagnosticFactory.on for creating diagnostics
In most cases it's better to use `FirDiagnosticReporter.reportOn`, so `on` methods now marked as opt in
This commit is contained in:
+12
-8
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.cfa.FirControlFlowChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.contracts.FirContractDescription
|
||||
import org.jetbrains.kotlin.fir.contracts.coneEffects
|
||||
import org.jetbrains.kotlin.fir.contracts.description.ConeCallsEffectDeclaration
|
||||
@@ -73,11 +74,9 @@ object FirCallsEffectAnalyzer : FirControlFlowChecker() {
|
||||
)
|
||||
|
||||
for ((symbol, leakedPlaces) in leakedSymbols) {
|
||||
function.contractDescription.source?.let {
|
||||
reporter.report(FirErrors.LEAKED_IN_PLACE_LAMBDA.on(it, symbol), context)
|
||||
}
|
||||
reporter.reportOn(function.contractDescription.source, FirErrors.LEAKED_IN_PLACE_LAMBDA, symbol, context)
|
||||
leakedPlaces.forEach {
|
||||
reporter.report(FirErrors.LEAKED_IN_PLACE_LAMBDA.on(it, symbol), context)
|
||||
reporter.reportOn(it, FirErrors.LEAKED_IN_PLACE_LAMBDA, symbol, context)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,10 +110,15 @@ object FirCallsEffectAnalyzer : FirControlFlowChecker() {
|
||||
): Boolean {
|
||||
val foundRange = info[symbol] ?: EventOccurrencesRange.ZERO
|
||||
if (foundRange !in requiredRange) {
|
||||
function.contractDescription.source?.let {
|
||||
reporter.report(FirErrors.WRONG_INVOCATION_KIND.on(it, symbol, requiredRange, foundRange), context)
|
||||
return true
|
||||
}
|
||||
reporter.reportOn(
|
||||
function.contractDescription.source,
|
||||
FirErrors.WRONG_INVOCATION_KIND,
|
||||
symbol,
|
||||
requiredRange,
|
||||
foundRange,
|
||||
context
|
||||
)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
+4
-8
@@ -80,10 +80,8 @@ object FirPropertyInitializationAnalyzer : AbstractFirPropertyInitializationChec
|
||||
}
|
||||
val kind = info[symbol] ?: EventOccurrencesRange.ZERO
|
||||
if (symbol.fir.isVal && kind.canBeRevisited()) {
|
||||
node.fir.lValue.source?.let {
|
||||
reporter.report(FirErrors.VAL_REASSIGNMENT.on(it, symbol), context)
|
||||
return true
|
||||
}
|
||||
reporter.reportOn(node.fir.lValue.source, FirErrors.VAL_REASSIGNMENT, symbol, context)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -109,10 +107,8 @@ object FirPropertyInitializationAnalyzer : AbstractFirPropertyInitializationChec
|
||||
): Boolean {
|
||||
val kind = info[symbol] ?: EventOccurrencesRange.ZERO
|
||||
if (!kind.isDefinitelyVisited()) {
|
||||
node.fir.source?.let {
|
||||
reporter.report(FirErrors.UNINITIALIZED_VARIABLE.on(it, symbol), context)
|
||||
return true
|
||||
}
|
||||
reporter.reportOn(node.fir.source, FirErrors.UNINITIALIZED_VARIABLE, symbol, context)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
+2
-3
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.isSupertypeOf
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.contracts.FirResolvedContractDescription
|
||||
import org.jetbrains.kotlin.fir.contracts.coneEffects
|
||||
import org.jetbrains.kotlin.fir.contracts.description.*
|
||||
@@ -63,9 +64,7 @@ object FirReturnsImpliesAnalyzer : FirControlFlowChecker() {
|
||||
}
|
||||
|
||||
if (wrongCondition) {
|
||||
function.contractDescription.source?.let {
|
||||
reporter.report(FirErrors.WRONG_IMPLIES_CONDITION.on(it), context)
|
||||
}
|
||||
reporter.reportOn(function.contractDescription.source, FirErrors.WRONG_IMPLIES_CONDITION, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,7 +567,7 @@ fun checkTypeMismatch(
|
||||
if (rValue.isNullLiteral && lValueType.nullability == ConeNullability.NOT_NULL) {
|
||||
reporter.reportOn(rValue.source, FirErrors.NULL_FOR_NONNULL_TYPE, context)
|
||||
} else {
|
||||
reporter.report(diagnosticFactory.on(source, lValueType, rValueType), context)
|
||||
reporter.reportOn(source, diagnosticFactory, lValueType, rValueType, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -617,4 +617,4 @@ fun extractTypeRefAndSourceFromTypeArgument(typeRef: FirTypeRef?, index: Int): P
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.extractTypeRefAndSourceFromTypeArgument
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
@@ -116,14 +117,13 @@ object FirClassVarianceChecker : FirClassChecker() {
|
||||
) {
|
||||
val factory =
|
||||
if (isInAbbreviation) FirErrors.TYPE_VARIANCE_CONFLICT_IN_EXPANDED_TYPE else FirErrors.TYPE_VARIANCE_CONFLICT
|
||||
reporter.report(
|
||||
factory.on(
|
||||
resultSource,
|
||||
typeParameter.symbol,
|
||||
typeParameter.variance,
|
||||
variance,
|
||||
containingType
|
||||
),
|
||||
reporter.reportOn(
|
||||
resultSource,
|
||||
factory,
|
||||
typeParameter.symbol,
|
||||
typeParameter.variance,
|
||||
variance,
|
||||
containingType,
|
||||
context
|
||||
)
|
||||
}
|
||||
@@ -167,4 +167,4 @@ object FirClassVarianceChecker : FirClassChecker() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.contracts.FirResolvedContractDescription
|
||||
import org.jetbrains.kotlin.fir.declarations.FirContractDescriptionOwner
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||
@@ -30,7 +31,7 @@ object FirContractChecker : FirFunctionChecker() {
|
||||
|
||||
// TODO: report on fine-grained locations, e.g., ... implies unresolved => report on unresolved, not the entire statement.
|
||||
// but, sometimes, it's just reported on `contract`...
|
||||
reporter.report(FirErrors.ERROR_IN_CONTRACT_DESCRIPTION.on(statement.source!!, UNEXPECTED_CONSTRUCTION), context)
|
||||
reporter.reportOn(statement.source, FirErrors.ERROR_IN_CONTRACT_DESCRIPTION, UNEXPECTED_CONSTRUCTION, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-10
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter
|
||||
@@ -23,28 +24,28 @@ object FirInapplicableLateinitChecker : FirPropertyChecker() {
|
||||
|
||||
when {
|
||||
declaration.isVal ->
|
||||
reporter.reportOn(declaration.source, "is allowed only on mutable properties", context)
|
||||
reporter.reportError(declaration.source, "is allowed only on mutable properties", context)
|
||||
|
||||
declaration.initializer != null -> if (declaration.isLocal) {
|
||||
reporter.reportOn(declaration.source, "is not allowed on local variables with initializer", context)
|
||||
reporter.reportError(declaration.source, "is not allowed on local variables with initializer", context)
|
||||
} else {
|
||||
reporter.reportOn(declaration.source, "is not allowed on properties with initializer", context)
|
||||
reporter.reportError(declaration.source, "is not allowed on properties with initializer", context)
|
||||
}
|
||||
|
||||
declaration.delegate != null ->
|
||||
reporter.reportOn(declaration.source, "is not allowed on delegated properties", context)
|
||||
reporter.reportError(declaration.source, "is not allowed on delegated properties", context)
|
||||
|
||||
declaration.isNullable() ->
|
||||
reporter.reportOn(declaration.source, "is not allowed on properties of a type with nullable upper bound", context)
|
||||
reporter.reportError(declaration.source, "is not allowed on properties of a type with nullable upper bound", context)
|
||||
|
||||
declaration.returnTypeRef.coneType.isPrimitiveOrNullablePrimitive -> if (declaration.isLocal) {
|
||||
reporter.reportOn(declaration.source, "is not allowed on local variables of primitive types", context)
|
||||
reporter.reportError(declaration.source, "is not allowed on local variables of primitive types", context)
|
||||
} else {
|
||||
reporter.reportOn(declaration.source, "is not allowed on properties of primitive types", context)
|
||||
reporter.reportError(declaration.source, "is not allowed on properties of primitive types", context)
|
||||
}
|
||||
|
||||
declaration.hasGetter() || declaration.hasSetter() ->
|
||||
reporter.reportOn(declaration.source, "is not allowed on properties with a custom getter or setter", context)
|
||||
reporter.reportError(declaration.source, "is not allowed on properties with a custom getter or setter", context)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +57,7 @@ object FirInapplicableLateinitChecker : FirPropertyChecker() {
|
||||
private fun FirProperty.hasGetter() = getter != null && getter !is FirDefaultPropertyGetter
|
||||
private fun FirProperty.hasSetter() = setter != null && setter !is FirDefaultPropertySetter
|
||||
|
||||
private fun DiagnosticReporter.reportOn(source: FirSourceElement?, target: String, context: CheckerContext) {
|
||||
source?.let { report(FirErrors.INAPPLICABLE_LATEINIT_MODIFIER.on(it, target), context) }
|
||||
private fun DiagnosticReporter.reportError(source: FirSourceElement?, target: String, context: CheckerContext) {
|
||||
reportOn(source, FirErrors.INAPPLICABLE_LATEINIT_MODIFIER, target, context)
|
||||
}
|
||||
}
|
||||
|
||||
+6
-3
@@ -41,13 +41,16 @@ object FirMemberFunctionsChecker : FirRegularClassChecker() {
|
||||
val isAbstract = function.isAbstract || hasAbstractModifier
|
||||
if (isAbstract) {
|
||||
if (!containingDeclaration.canHaveAbstractDeclaration) {
|
||||
reporter.report(
|
||||
FirErrors.ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS.on(source, function, containingDeclaration),
|
||||
reporter.reportOn(
|
||||
source,
|
||||
FirErrors.ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS,
|
||||
function,
|
||||
containingDeclaration,
|
||||
context
|
||||
)
|
||||
}
|
||||
if (function.hasBody) {
|
||||
reporter.report(FirErrors.ABSTRACT_FUNCTION_WITH_BODY.on(source, function), context)
|
||||
reporter.reportOn(source, FirErrors.ABSTRACT_FUNCTION_WITH_BODY, function, context)
|
||||
}
|
||||
}
|
||||
val isInsideExpectClass = isInsideExpectClass(containingDeclaration, context)
|
||||
|
||||
+5
-4
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.getModifierList
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
@@ -179,24 +180,24 @@ object FirModifierChecker : FirBasicDeclarationChecker() {
|
||||
private fun DiagnosticReporter.reportRepeatedModifier(
|
||||
modifier: FirModifier<*>, keyword: KtModifierKeywordToken, context: CheckerContext
|
||||
) {
|
||||
report(FirErrors.REPEATED_MODIFIER.on(modifier.source, keyword), context)
|
||||
reportOn(modifier.source, FirErrors.REPEATED_MODIFIER, keyword, context)
|
||||
}
|
||||
|
||||
private fun DiagnosticReporter.reportRedundantModifier(
|
||||
modifier: FirModifier<*>, firstKeyword: KtModifierKeywordToken, secondKeyword: KtModifierKeywordToken, context: CheckerContext
|
||||
) {
|
||||
report(FirErrors.REDUNDANT_MODIFIER.on(modifier.source, firstKeyword, secondKeyword), context)
|
||||
reportOn(modifier.source, FirErrors.REDUNDANT_MODIFIER, firstKeyword, secondKeyword, context)
|
||||
}
|
||||
|
||||
private fun DiagnosticReporter.reportDeprecatedModifierPair(
|
||||
modifier: FirModifier<*>, firstKeyword: KtModifierKeywordToken, secondKeyword: KtModifierKeywordToken, context: CheckerContext
|
||||
) {
|
||||
report(FirErrors.DEPRECATED_MODIFIER_PAIR.on(modifier.source, firstKeyword, secondKeyword), context)
|
||||
reportOn(modifier.source, FirErrors.DEPRECATED_MODIFIER_PAIR, firstKeyword, secondKeyword, context)
|
||||
}
|
||||
|
||||
private fun DiagnosticReporter.reportIncompatibleModifiers(
|
||||
modifier: FirModifier<*>, firstKeyword: KtModifierKeywordToken, secondKeyword: KtModifierKeywordToken, context: CheckerContext
|
||||
) {
|
||||
report(FirErrors.INCOMPATIBLE_MODIFIERS.on(modifier.source, firstKeyword, secondKeyword), context)
|
||||
reportOn(modifier.source, FirErrors.INCOMPATIBLE_MODIFIERS, firstKeyword, secondKeyword, context)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -242,10 +242,8 @@ object FirOverrideChecker : FirClassChecker() {
|
||||
overridden: FirCallableDeclaration<*>,
|
||||
context: CheckerContext
|
||||
) {
|
||||
overriding.source?.let { source ->
|
||||
overridden.containingClass()?.let { containingClass ->
|
||||
report(FirErrors.OVERRIDING_FINAL_MEMBER.on(source, overridden, containingClass.name), context)
|
||||
}
|
||||
overridden.containingClass()?.let { containingClass ->
|
||||
reportOn(overriding.source, FirErrors.OVERRIDING_FINAL_MEMBER, overridden, containingClass.name, context)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,7 +252,7 @@ object FirOverrideChecker : FirClassChecker() {
|
||||
overridden: FirMemberDeclaration,
|
||||
context: CheckerContext
|
||||
) {
|
||||
overriding.source?.let { report(FirErrors.VAR_OVERRIDDEN_BY_VAL.on(it, overriding, overridden), context) }
|
||||
reportOn(overriding.source, FirErrors.VAR_OVERRIDDEN_BY_VAL, overriding, overridden, context)
|
||||
}
|
||||
|
||||
private fun DiagnosticReporter.reportCannotWeakenAccessPrivilege(
|
||||
|
||||
+7
-4
@@ -35,7 +35,6 @@ object FirFunctionReturnTypeMismatchChecker : FirReturnExpressionChecker() {
|
||||
val returnExpressionType = resultExpression.typeRef.coneTypeSafe<ConeKotlinType>() ?: return
|
||||
|
||||
if (!isSubtypeForTypeMismatch(typeContext, subtype = returnExpressionType, supertype = functionReturnType)) {
|
||||
val returnExpressionSource = resultExpression.source ?: return
|
||||
if (resultExpression.isNullLiteral && functionReturnType.nullability == ConeNullability.NOT_NULL) {
|
||||
reporter.reportOn(resultExpression.source, NULL_FOR_NONNULL_TYPE, context)
|
||||
} else {
|
||||
@@ -51,12 +50,16 @@ object FirFunctionReturnTypeMismatchChecker : FirReturnExpressionChecker() {
|
||||
context
|
||||
)
|
||||
} else {
|
||||
reporter.report(
|
||||
RETURN_TYPE_MISMATCH.on(returnExpressionSource, functionReturnType, returnExpressionType, targetElement),
|
||||
reporter.reportOn(
|
||||
resultExpression.source,
|
||||
RETURN_TYPE_MISMATCH,
|
||||
functionReturnType,
|
||||
returnExpressionType,
|
||||
targetElement,
|
||||
context
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -16,6 +16,7 @@ abstract class DiagnosticReporter {
|
||||
abstract fun report(diagnostic: FirDiagnostic<*>?, context: CheckerContext)
|
||||
}
|
||||
|
||||
@OptIn(InternalDiagnosticFactoryMethod::class)
|
||||
fun <P : PsiElement> DiagnosticReporter.reportOn(
|
||||
source: FirSourceElement?,
|
||||
factory: FirDiagnosticFactory0<P>,
|
||||
@@ -24,6 +25,7 @@ fun <P : PsiElement> DiagnosticReporter.reportOn(
|
||||
source?.let { report(factory.on(it), context) }
|
||||
}
|
||||
|
||||
@OptIn(InternalDiagnosticFactoryMethod::class)
|
||||
fun <P : PsiElement, A : Any> DiagnosticReporter.reportOn(
|
||||
source: FirSourceElement?,
|
||||
factory: FirDiagnosticFactory1<P, A>,
|
||||
@@ -33,6 +35,7 @@ fun <P : PsiElement, A : Any> DiagnosticReporter.reportOn(
|
||||
source?.let { report(factory.on(it, a), context) }
|
||||
}
|
||||
|
||||
@OptIn(InternalDiagnosticFactoryMethod::class)
|
||||
fun <P : PsiElement, A : Any, B : Any> DiagnosticReporter.reportOn(
|
||||
source: FirSourceElement?,
|
||||
factory: FirDiagnosticFactory2<P, A, B>,
|
||||
@@ -43,6 +46,7 @@ fun <P : PsiElement, A : Any, B : Any> DiagnosticReporter.reportOn(
|
||||
source?.let { report(factory.on(it, a, b), context) }
|
||||
}
|
||||
|
||||
@OptIn(InternalDiagnosticFactoryMethod::class)
|
||||
fun <P : PsiElement, A : Any, B : Any, C : Any> DiagnosticReporter.reportOn(
|
||||
source: FirSourceElement?,
|
||||
factory: FirDiagnosticFactory3<P, A, B, C>,
|
||||
@@ -54,6 +58,7 @@ fun <P : PsiElement, A : Any, B : Any, C : Any> DiagnosticReporter.reportOn(
|
||||
source?.let { report(factory.on(it, a, b, c), context) }
|
||||
}
|
||||
|
||||
@OptIn(InternalDiagnosticFactoryMethod::class)
|
||||
fun <P : PsiElement, A : Any, B : Any, C : Any, D : Any> DiagnosticReporter.reportOn(
|
||||
source: FirSourceElement?,
|
||||
factory: FirDiagnosticFactory4<P, A, B, C, D>,
|
||||
|
||||
+14
-1
@@ -16,6 +16,9 @@ import org.jetbrains.kotlin.fir.FirLightSourceElement
|
||||
import org.jetbrains.kotlin.fir.FirPsiSourceElement
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
|
||||
@RequiresOptIn("Please use DiagnosticReporter.reportOn method if possible")
|
||||
annotation class InternalDiagnosticFactoryMethod
|
||||
|
||||
sealed class AbstractFirDiagnosticFactory<D : FirDiagnostic<*>, P : PsiElement>(
|
||||
override val name: String,
|
||||
override val severity: Severity,
|
||||
@@ -44,6 +47,7 @@ class FirDiagnosticFactory0<P : PsiElement>(
|
||||
) : AbstractFirDiagnosticFactory<FirSimpleDiagnostic<*>, P>(name, severity, positioningStrategy) {
|
||||
override val firRenderer: FirDiagnosticRenderer<FirSimpleDiagnostic<*>> = SimpleFirDiagnosticRenderer("")
|
||||
|
||||
@InternalDiagnosticFactoryMethod
|
||||
fun on(element: FirSourceElement): FirSimpleDiagnostic<*> {
|
||||
return when (element) {
|
||||
is FirPsiSourceElement<*> -> FirPsiSimpleDiagnostic(
|
||||
@@ -65,6 +69,7 @@ class FirDiagnosticFactory1<P : PsiElement, A>(
|
||||
FirDiagnosticRenderers.TO_STRING
|
||||
)
|
||||
|
||||
@InternalDiagnosticFactoryMethod
|
||||
fun on(element: FirSourceElement, a: A): FirDiagnosticWithParameters1<*, A> {
|
||||
return when (element) {
|
||||
is FirPsiSourceElement<*> -> FirPsiDiagnosticWithParameters1(
|
||||
@@ -87,6 +92,7 @@ class FirDiagnosticFactory2<P : PsiElement, A, B>(
|
||||
FirDiagnosticRenderers.TO_STRING
|
||||
)
|
||||
|
||||
@InternalDiagnosticFactoryMethod
|
||||
fun on(element: FirSourceElement, a: A, b: B): FirDiagnosticWithParameters2<*, A, B> {
|
||||
return when (element) {
|
||||
is FirPsiSourceElement<*> -> FirPsiDiagnosticWithParameters2(
|
||||
@@ -110,6 +116,7 @@ class FirDiagnosticFactory3<P : PsiElement, A, B, C>(
|
||||
FirDiagnosticRenderers.TO_STRING
|
||||
)
|
||||
|
||||
@InternalDiagnosticFactoryMethod
|
||||
fun on(element: FirSourceElement, a: A, b: B, c: C): FirDiagnosticWithParameters3<*, A, B, C> {
|
||||
return when (element) {
|
||||
is FirPsiSourceElement<*> -> FirPsiDiagnosticWithParameters3(
|
||||
@@ -134,6 +141,7 @@ class FirDiagnosticFactory4<P : PsiElement, A, B, C, D>(
|
||||
FirDiagnosticRenderers.TO_STRING
|
||||
)
|
||||
|
||||
@InternalDiagnosticFactoryMethod
|
||||
fun on(element: FirSourceElement, a: A, b: B, c: C, d: D): FirDiagnosticWithParameters4<*, A, B, C, D> {
|
||||
return when (element) {
|
||||
is FirPsiSourceElement<*> -> FirPsiDiagnosticWithParameters4(
|
||||
@@ -149,16 +157,19 @@ private fun incorrectElement(element: FirSourceElement): Nothing {
|
||||
throw IllegalArgumentException("Unknown element type: ${element::class}")
|
||||
}
|
||||
|
||||
@InternalDiagnosticFactoryMethod
|
||||
fun <P : PsiElement> FirDiagnosticFactory0<P>.on(element: FirSourceElement?): FirSimpleDiagnostic<*>? {
|
||||
return element?.let { on(it) }
|
||||
}
|
||||
|
||||
@InternalDiagnosticFactoryMethod
|
||||
fun <P : PsiElement, A> FirDiagnosticFactory1<P, A>.on(
|
||||
element: FirSourceElement?, a: A
|
||||
): FirDiagnosticWithParameters1<*, A>? {
|
||||
return element?.let { on(it, a) }
|
||||
}
|
||||
|
||||
@InternalDiagnosticFactoryMethod
|
||||
fun <P : PsiElement, A, B> FirDiagnosticFactory2<P, A, B>.on(
|
||||
element: FirSourceElement?,
|
||||
a: A,
|
||||
@@ -167,6 +178,7 @@ fun <P : PsiElement, A, B> FirDiagnosticFactory2<P, A, B>.on(
|
||||
return element?.let { on(it, a, b) }
|
||||
}
|
||||
|
||||
@InternalDiagnosticFactoryMethod
|
||||
fun <P : PsiElement, A, B, C> FirDiagnosticFactory3<P, A, B, C>.on(
|
||||
element: FirSourceElement?,
|
||||
a: A,
|
||||
@@ -176,6 +188,7 @@ fun <P : PsiElement, A, B, C> FirDiagnosticFactory3<P, A, B, C>.on(
|
||||
return element?.let { on(it, a, b, c) }
|
||||
}
|
||||
|
||||
@InternalDiagnosticFactoryMethod
|
||||
fun <P : PsiElement, A, B, C, D> FirDiagnosticFactory4<P, A, B, C, D>.on(
|
||||
element: FirSourceElement?,
|
||||
a: A,
|
||||
@@ -184,4 +197,4 @@ fun <P : PsiElement, A, B, C, D> FirDiagnosticFactory4<P, A, B, C, D>.on(
|
||||
d: D
|
||||
): FirDiagnosticWithParameters4<*, A, B, C, D>? {
|
||||
return element?.let { on(it, a, b, c, d) }
|
||||
}
|
||||
}
|
||||
|
||||
+7
-3
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
@OptIn(InternalDiagnosticFactoryMethod::class)
|
||||
private fun ConeDiagnostic.toFirDiagnostic(
|
||||
source: FirSourceElement,
|
||||
qualifiedAccessSource: FirSourceElement?
|
||||
@@ -73,7 +74,7 @@ private fun ConeDiagnostic.toFirDiagnostic(
|
||||
FirErrors.NO_TYPE_ARGUMENTS_ON_RHS.on(qualifiedAccessSource ?: source, this.desiredCount, this.type)
|
||||
is ConeSimpleDiagnostic -> when (source.kind) {
|
||||
is FirFakeSourceElementKind -> null
|
||||
else -> this.getFactory(source)?.on(qualifiedAccessSource ?: source)
|
||||
else -> this.getFactory(source).on(qualifiedAccessSource ?: source)
|
||||
}
|
||||
is ConeInstanceAccessBeforeSuperCall -> FirErrors.INSTANCE_ACCESS_BEFORE_SUPER_CALL.on(source, this.target)
|
||||
is ConeStubDiagnostic -> null
|
||||
@@ -97,6 +98,7 @@ fun ConeDiagnostic.toFirDiagnostics(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(InternalDiagnosticFactoryMethod::class)
|
||||
private fun mapUnsafeCallError(
|
||||
candidate: Candidate,
|
||||
rootCause: UnsafeCall,
|
||||
@@ -146,6 +148,7 @@ private fun mapUnsafeCallError(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(InternalDiagnosticFactoryMethod::class)
|
||||
private fun mapInapplicableCandidateError(
|
||||
diagnostic: ConeInapplicableCandidateError,
|
||||
source: FirSourceElement,
|
||||
@@ -200,7 +203,7 @@ private fun mapInapplicableCandidateError(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
@OptIn(ExperimentalStdlibApi::class, InternalDiagnosticFactoryMethod::class)
|
||||
private fun mapSystemHasContradictionError(
|
||||
diagnostic: ConeConstraintSystemHasContradiction,
|
||||
source: FirSourceElement,
|
||||
@@ -244,6 +247,7 @@ private fun mapSystemHasContradictionError(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(InternalDiagnosticFactoryMethod::class)
|
||||
private fun ConstraintSystemError.toDiagnostic(
|
||||
source: FirSourceElement,
|
||||
qualifiedAccessSource: FirSourceElement?,
|
||||
@@ -327,7 +331,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
|
||||
|
||||
+1
@@ -111,6 +111,7 @@ class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(tes
|
||||
return metaInfo
|
||||
}
|
||||
|
||||
@OptIn(InternalDiagnosticFactoryMethod::class)
|
||||
private fun collectSyntaxDiagnostics(
|
||||
testFile: TestFile,
|
||||
firFile: FirFile,
|
||||
|
||||
Reference in New Issue
Block a user