[FIR] UPPER_BOUND_CANNOT_BE_ARRAY diagnostic

This commit is contained in:
Andrey Zinovyev
2021-08-18 16:00:24 +03:00
committed by TeamCityServer
parent 4661656b8c
commit 24fbe0f072
9 changed files with 56 additions and 19 deletions
@@ -29,6 +29,10 @@ object JVM_DIAGNOSTICS_LIST : DiagnosticList("FirJvmErrors") {
}
}
val TYPE_PARAMETERS by object : DiagnosticGroup("Type parameters") {
val UPPER_BOUND_CANNOT_BE_ARRAY by error<PsiElement>()
}
val ANNOTATIONS by object : DiagnosticGroup("annotations") {
val STRICTFP_ON_CLASS by error<KtAnnotationEntry>()
val VOLATILE_ON_VALUE by error<KtAnnotationEntry>()
@@ -25,6 +25,9 @@ object FirJvmErrors {
// Types
val JAVA_TYPE_MISMATCH by error2<KtExpression, ConeKotlinType, ConeKotlinType>()
// Type parameters
val UPPER_BOUND_CANNOT_BE_ARRAY by error0<PsiElement>()
// annotations
val STRICTFP_ON_CLASS by error0<KtAnnotationEntry>()
val VOLATILE_ON_VALUE by error0<KtAnnotationEntry>()
@@ -16,7 +16,7 @@ object JvmDeclarationCheckers : DeclarationCheckers() {
override val classCheckers: Set<FirClassChecker>
get() = setOf(
FirStrictfpApplicabilityChecker
FirStrictfpApplicabilityChecker,
)
override val propertyCheckers: Set<FirPropertyChecker>
@@ -29,4 +29,9 @@ object JvmDeclarationCheckers : DeclarationCheckers() {
FirSynchronizedAnnotationChecker,
FirOverloadsChecker,
)
override val typeParameterCheckers: Set<FirTypeParameterChecker>
get() = setOf(
FirUpperBoundsChecker,
)
}
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.analysis.jvm.checkers.declaration
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirTypeParameterChecker
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.isArrayType
object FirUpperBoundsChecker : FirTypeParameterChecker() {
override fun check(declaration: FirTypeParameter, context: CheckerContext, reporter: DiagnosticReporter) {
if (declaration.bounds.any { it.coneType.isArrayType }) {
reporter.reportOn(declaration.source, FirJvmErrors.UPPER_BOUND_CANNOT_BE_ARRAY, context)
}
}
}
@@ -1,18 +0,0 @@
fun <A : Array<Any>> f1() {}
fun <T, A : Array<out T>> f2() {}
fun <S, T : S, A> f3() where A : Array<out S>, A : <!REPEATED_BOUND!>Array<out T><!> {}
fun <T : <!FINAL_UPPER_BOUND!>IntArray<!>> f4() {}
fun <T> f5() where T : Array<Any> {}
val <T : Array<Any?>> T.v: String get() = ""
class C2<T, A : Array<out T>>
interface C3<S, T : S, A> where A : Array<out S>, A : <!REPEATED_BOUND!>Array<out T><!>
fun foo() {
class C1<A : Array<Any>> {
fun <A : Array<Any>, B : Array<Any>, C : A> f() {}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
fun <<!UPPER_BOUND_CANNOT_BE_ARRAY!>A : Array<Any><!>> f1() {}
fun <T, <!UPPER_BOUND_CANNOT_BE_ARRAY!>A : Array<out T><!>> f2() {}
fun <S, T : S, <!UPPER_BOUND_CANNOT_BE_ARRAY!>A<!>> f3() where A : Array<out S>, A : <!REPEATED_BOUND!>Array<out T><!> {}
@@ -3447,6 +3447,12 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirJvmErrors.UPPER_BOUND_CANNOT_BE_ARRAY) { firDiagnostic ->
UpperBoundCannotBeArrayImpl(
firDiagnostic as FirPsiDiagnostic,
token,
)
}
add(FirJvmErrors.STRICTFP_ON_CLASS) { firDiagnostic ->
StrictfpOnClassImpl(
firDiagnostic as FirPsiDiagnostic,
@@ -2404,6 +2404,10 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
abstract val actualType: KtType
}
abstract class UpperBoundCannotBeArray : KtFirDiagnostic<PsiElement>() {
override val diagnosticClass get() = UpperBoundCannotBeArray::class
}
abstract class StrictfpOnClass : KtFirDiagnostic<KtAnnotationEntry>() {
override val diagnosticClass get() = StrictfpOnClass::class
}
@@ -3887,6 +3887,13 @@ internal class JavaTypeMismatchImpl(
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
}
internal class UpperBoundCannotBeArrayImpl(
firDiagnostic: FirPsiDiagnostic,
override val token: ValidityToken,
) : KtFirDiagnostic.UpperBoundCannotBeArray(), KtAbstractFirDiagnostic<PsiElement> {
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
}
internal class StrictfpOnClassImpl(
firDiagnostic: FirPsiDiagnostic,
override val token: ValidityToken,