Minor fixes around FirKClassWithIncorrectTypeArgumentChecker
This commit is contained in:
+3
-6
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.fir.resolve.inference.isKClassType
|
|||||||
import org.jetbrains.kotlin.fir.scopes.impl.toConeType
|
import org.jetbrains.kotlin.fir.scopes.impl.toConeType
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
|
|
||||||
// FE1.0 [KClassWithIncorrectTypeArgumentChecker]
|
// See FE1.0 [KClassWithIncorrectTypeArgumentChecker]
|
||||||
object FirKClassWithIncorrectTypeArgumentChecker : FirFileChecker() {
|
object FirKClassWithIncorrectTypeArgumentChecker : FirFileChecker() {
|
||||||
override fun check(declaration: FirFile, context: CheckerContext, reporter: DiagnosticReporter) {
|
override fun check(declaration: FirFile, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
for (topLevelDeclaration in declaration.declarations) {
|
for (topLevelDeclaration in declaration.declarations) {
|
||||||
@@ -36,14 +36,11 @@ object FirKClassWithIncorrectTypeArgumentChecker : FirFileChecker() {
|
|||||||
context: CheckerContext,
|
context: CheckerContext,
|
||||||
reporter: DiagnosticReporter
|
reporter: DiagnosticReporter
|
||||||
) {
|
) {
|
||||||
// prevent duplicate reporting
|
|
||||||
if (declaration is FirPropertyAccessor) return
|
|
||||||
|
|
||||||
val source = declaration.source ?: return
|
val source = declaration.source ?: return
|
||||||
if (source.kind is FirFakeSourceElementKind) return
|
if (source.kind is FirFakeSourceElementKind) return
|
||||||
|
|
||||||
val returnType = declaration.returnTypeRef.coneType
|
val returnType = declaration.returnTypeRef.coneType
|
||||||
if (!returnType.isKClassWithBadArgument(context.session)) return
|
if (!returnType.isKClassTypeWithErrorOrNullableArgument(context.session)) return
|
||||||
|
|
||||||
val typeArgument = (returnType.typeArguments[0] as ConeKotlinTypeProjection).type
|
val typeArgument = (returnType.typeArguments[0] as ConeKotlinTypeProjection).type
|
||||||
typeArgument.typeParameterFromError?.let {
|
typeArgument.typeParameterFromError?.let {
|
||||||
@@ -51,7 +48,7 @@ object FirKClassWithIncorrectTypeArgumentChecker : FirFileChecker() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ConeKotlinType.isKClassWithBadArgument(session: FirSession): Boolean {
|
private fun ConeKotlinType.isKClassTypeWithErrorOrNullableArgument(session: FirSession): Boolean {
|
||||||
if (!this.isKClassType()) return false
|
if (!this.isKClassType()) return false
|
||||||
val argumentType = typeArguments.toList().singleOrNull()?.let {
|
val argumentType = typeArguments.toList().singleOrNull()?.let {
|
||||||
when (it) {
|
when (it) {
|
||||||
|
|||||||
+1
@@ -51,6 +51,7 @@ private fun ConeDiagnostic.toFirDiagnostic(source: FirSourceElement): FirDiagnos
|
|||||||
is ConeIntermediateDiagnostic -> null
|
is ConeIntermediateDiagnostic -> null
|
||||||
is ConeContractDescriptionError -> FirErrors.ERROR_IN_CONTRACT_DESCRIPTION.on(source, this.reason)
|
is ConeContractDescriptionError -> FirErrors.ERROR_IN_CONTRACT_DESCRIPTION.on(source, this.reason)
|
||||||
is ConeTypeParameterSupertype -> FirErrors.SUPERTYPE_NOT_A_CLASS_OR_INTERFACE.on(source, this.reason)
|
is ConeTypeParameterSupertype -> FirErrors.SUPERTYPE_NOT_A_CLASS_OR_INTERFACE.on(source, this.reason)
|
||||||
|
is ConeTypeParameterInQualifiedAccess -> null // reported in various checkers instead
|
||||||
else -> throw IllegalArgumentException("Unsupported diagnostic type: ${this.javaClass}")
|
else -> throw IllegalArgumentException("Unsupported diagnostic type: ${this.javaClass}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user