Use reportOn in FirThrowableSubclassChecker & FirCatchParameterChecker
This commit is contained in:
+4
-12
@@ -5,11 +5,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.isThrowable
|
import org.jetbrains.kotlin.fir.analysis.checkers.isThrowable
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
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.*
|
||||||
import org.jetbrains.kotlin.fir.types.ConeClassErrorType
|
import org.jetbrains.kotlin.fir.types.ConeClassErrorType
|
||||||
|
|
||||||
@@ -19,16 +19,16 @@ object FirThrowableSubclassChecker : FirClassChecker() {
|
|||||||
return
|
return
|
||||||
|
|
||||||
if (declaration.typeParameters.isNotEmpty()) {
|
if (declaration.typeParameters.isNotEmpty()) {
|
||||||
reporter.reportGenericThrowableSubclass(declaration.typeParameters.firstOrNull()?.source)
|
reporter.reportOn(declaration.typeParameters.firstOrNull()?.source, FirErrors.GENERIC_THROWABLE_SUBCLASS, context)
|
||||||
|
|
||||||
val source = when {
|
val source = when {
|
||||||
(declaration as? FirRegularClass)?.isInner == true -> declaration.source
|
(declaration as? FirRegularClass)?.isInner == true -> declaration.source
|
||||||
declaration is FirAnonymousObject -> (declaration.declarations.firstOrNull())?.source
|
declaration is FirAnonymousObject -> (declaration.declarations.firstOrNull())?.source
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
reporter.reportInnerClassOfGenericThrowableSubclass(source)
|
reporter.reportOn(source, FirErrors.INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS, context)
|
||||||
} else if (declaration.hasGenericOuterDeclaration(context)) {
|
} else if (declaration.hasGenericOuterDeclaration(context)) {
|
||||||
reporter.reportInnerClassOfGenericThrowableSubclass(declaration.source)
|
reporter.reportOn(declaration.source, FirErrors.INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,12 +40,4 @@ object FirThrowableSubclassChecker : FirClassChecker() {
|
|||||||
|
|
||||||
private fun Collection<FirDeclaration>.anyIsGeneric() =
|
private fun Collection<FirDeclaration>.anyIsGeneric() =
|
||||||
any { it is FirTypeParameterRefsOwner && it.typeParameters.isNotEmpty() }
|
any { it is FirTypeParameterRefsOwner && it.typeParameters.isNotEmpty() }
|
||||||
|
|
||||||
private fun DiagnosticReporter.reportGenericThrowableSubclass(source: FirSourceElement?) {
|
|
||||||
source?.let { report(FirErrors.GENERIC_THROWABLE_SUBCLASS.on(it)) }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun DiagnosticReporter.reportInnerClassOfGenericThrowableSubclass(source: FirSourceElement?) {
|
|
||||||
source?.let { report(FirErrors.INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS.on(it)) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+9
-13
@@ -5,29 +5,24 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.analysis.checkers.expression
|
package org.jetbrains.kotlin.fir.analysis.checkers.expression
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
|
||||||
import org.jetbrains.kotlin.fir.analysis.cfa.FirReturnsImpliesAnalyzer.isSupertypeOf
|
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.isThrowable
|
import org.jetbrains.kotlin.fir.analysis.checkers.isThrowable
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.throwableClassLikeType
|
import org.jetbrains.kotlin.fir.analysis.checkers.throwableClassLikeType
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirTryExpression
|
import org.jetbrains.kotlin.fir.expressions.FirTryExpression
|
||||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
|
||||||
import org.jetbrains.kotlin.fir.typeCheckerContext
|
|
||||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
|
||||||
import org.jetbrains.kotlin.fir.types.ConeTypeParameterType
|
import org.jetbrains.kotlin.fir.types.ConeTypeParameterType
|
||||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.constructClassLikeType
|
|
||||||
|
|
||||||
object FirCatchParameterChecker : FirTryExpressionChecker() {
|
object FirCatchParameterChecker : FirTryExpressionChecker() {
|
||||||
override fun check(expression: FirTryExpression, context: CheckerContext, reporter: DiagnosticReporter) {
|
override fun check(expression: FirTryExpression, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
for (catchEntry in expression.catches) {
|
for (catchEntry in expression.catches) {
|
||||||
val catchParameter = catchEntry.parameter
|
val catchParameter = catchEntry.parameter
|
||||||
|
|
||||||
if (catchParameter.defaultValue != null)
|
if (catchParameter.defaultValue != null) {
|
||||||
catchParameter.source?.let { reporter.report(FirErrors.CATCH_PARAMETER_WITH_DEFAULT_VALUE.on(it), context) }
|
reporter.reportOn(catchParameter.source, FirErrors.CATCH_PARAMETER_WITH_DEFAULT_VALUE, context)
|
||||||
|
}
|
||||||
|
|
||||||
val typeRef = catchParameter.returnTypeRef
|
val typeRef = catchParameter.returnTypeRef
|
||||||
if (typeRef !is FirResolvedTypeRef) return
|
if (typeRef !is FirResolvedTypeRef) return
|
||||||
@@ -37,14 +32,15 @@ object FirCatchParameterChecker : FirTryExpressionChecker() {
|
|||||||
val isReified = coneType.lookupTag.typeParameterSymbol.fir.isReified
|
val isReified = coneType.lookupTag.typeParameterSymbol.fir.isReified
|
||||||
|
|
||||||
if (isReified) {
|
if (isReified) {
|
||||||
catchParameter.source?.let { reporter.report(FirErrors.REIFIED_TYPE_IN_CATCH_CLAUSE.on(it), context) }
|
reporter.reportOn(catchParameter.source, FirErrors.REIFIED_TYPE_IN_CATCH_CLAUSE, context)
|
||||||
} else {
|
} else {
|
||||||
catchParameter.source?.let { reporter.report(FirErrors.TYPE_PARAMETER_IN_CATCH_CLAUSE.on(it), context) }
|
reporter.reportOn(catchParameter.source, FirErrors.TYPE_PARAMETER_IN_CATCH_CLAUSE, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!coneType.isThrowable(context.session))
|
if (!coneType.isThrowable(context.session)) {
|
||||||
catchParameter.source?.let { reporter.report(FirErrors.TYPE_MISMATCH.on(it, throwableClassLikeType, coneType), context) }
|
reporter.reportOn(catchParameter.source, FirErrors.TYPE_MISMATCH, throwableClassLikeType, coneType, context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user