[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 ->