[FIR] Add JVM_RECORD_NOT_LAST_VARARG_PARAMETER diagnostic

This commit is contained in:
Andrey Zinovyev
2021-08-19 13:33:51 +03:00
committed by Space
parent bf845b6066
commit 49484c4292
6 changed files with 29 additions and 3 deletions
@@ -68,6 +68,7 @@ object JVM_DIAGNOSTICS_LIST : DiagnosticList("FirJvmErrors") {
val JVM_RECORD_WITHOUT_PRIMARY_CONSTRUCTOR_PARAMETERS by error<PsiElement>()
val NON_DATA_CLASS_JVM_RECORD by error<PsiElement>()
val JVM_RECORD_NOT_VAL_PARAMETER by error<PsiElement>()
val JVM_RECORD_NOT_LAST_VARARG_PARAMETER by error<PsiElement>()
}
}
@@ -57,5 +57,6 @@ object FirJvmErrors {
val JVM_RECORD_WITHOUT_PRIMARY_CONSTRUCTOR_PARAMETERS by error0<PsiElement>()
val NON_DATA_CLASS_JVM_RECORD by error0<PsiElement>()
val JVM_RECORD_NOT_VAL_PARAMETER by error0<PsiElement>()
val JVM_RECORD_NOT_LAST_VARARG_PARAMETER by error0<PsiElement>()
}
@@ -58,9 +58,16 @@ object FirJvmRecordChecker : FirRegularClassChecker() {
return
}
if (declaration.primaryConstructor?.valueParameters?.isEmpty() == true) {
reporter.reportOn(annotationSource, FirJvmErrors.JVM_RECORD_WITHOUT_PRIMARY_CONSTRUCTOR_PARAMETERS, context)
return
declaration.primaryConstructor?.valueParameters?.let { params ->
if (params.isEmpty()) {
reporter.reportOn(annotationSource, FirJvmErrors.JVM_RECORD_WITHOUT_PRIMARY_CONSTRUCTOR_PARAMETERS, context)
return
}
params.dropLast(1).forEach { param ->
if (param.isVararg) {
reporter.reportOn(param.source, FirJvmErrors.JVM_RECORD_NOT_LAST_VARARG_PARAMETER, context)
}
}
}
declaration.declarations.forEach { decl ->
@@ -3574,4 +3574,10 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirJvmErrors.JVM_RECORD_NOT_LAST_VARARG_PARAMETER) { firDiagnostic ->
JvmRecordNotLastVarargParameterImpl(
firDiagnostic as FirPsiDiagnostic,
token,
)
}
}
@@ -2489,4 +2489,8 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
override val diagnosticClass get() = JvmRecordNotValParameter::class
}
abstract class JvmRecordNotLastVarargParameter : KtFirDiagnostic<PsiElement>() {
override val diagnosticClass get() = JvmRecordNotLastVarargParameter::class
}
}
@@ -4035,3 +4035,10 @@ internal class JvmRecordNotValParameterImpl(
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
}
internal class JvmRecordNotLastVarargParameterImpl(
firDiagnostic: FirPsiDiagnostic,
override val token: ValidityToken,
) : KtFirDiagnostic.JvmRecordNotLastVarargParameter(), KtAbstractFirDiagnostic<PsiElement> {
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
}