[FIR] Add FIELD_IN_JVM_RECORD diagnostic
This commit is contained in:
+1
@@ -70,6 +70,7 @@ object JVM_DIAGNOSTICS_LIST : DiagnosticList("FirJvmErrors") {
|
||||
val JVM_RECORD_NOT_VAL_PARAMETER by error<PsiElement>()
|
||||
val JVM_RECORD_NOT_LAST_VARARG_PARAMETER by error<PsiElement>()
|
||||
val INNER_JVM_RECORD by error<PsiElement>(PositioningStrategy.INNER_MODIFIER)
|
||||
val FIELD_IN_JVM_RECORD by error<PsiElement>()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
@@ -59,5 +59,6 @@ object FirJvmErrors {
|
||||
val JVM_RECORD_NOT_VAL_PARAMETER by error0<PsiElement>()
|
||||
val JVM_RECORD_NOT_LAST_VARARG_PARAMETER by error0<PsiElement>()
|
||||
val INNER_JVM_RECORD by error0<PsiElement>(SourceElementPositioningStrategies.INNER_MODIFIER)
|
||||
val FIELD_IN_JVM_RECORD by error0<PsiElement>()
|
||||
|
||||
}
|
||||
|
||||
+4
-1
@@ -77,8 +77,11 @@ object FirJvmRecordChecker : FirRegularClassChecker() {
|
||||
|
||||
declaration.declarations.forEach { decl ->
|
||||
if (decl is FirProperty) {
|
||||
if (decl.isVar && decl.source?.kind == FirFakeSourceElementKind.PropertyFromParameter) {
|
||||
val fromConstructor = decl.source?.kind == FirFakeSourceElementKind.PropertyFromParameter
|
||||
if (decl.isVar && fromConstructor) {
|
||||
reporter.reportOn(decl.source, FirJvmErrors.JVM_RECORD_NOT_VAL_PARAMETER, context)
|
||||
} else if (!fromConstructor && (decl.hasBackingField || decl.delegateFieldSymbol != null)) {
|
||||
reporter.reportOn(decl.source, FirJvmErrors.FIELD_IN_JVM_RECORD, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -13,13 +13,13 @@ data class MyRec1(val name: String) : I by i
|
||||
|
||||
@JvmRecord
|
||||
data class MyRec2(val name: String) {
|
||||
val x: Int = 0
|
||||
<!FIELD_IN_JVM_RECORD!>val x: Int = 0<!>
|
||||
}
|
||||
|
||||
@JvmRecord
|
||||
data class MyRec3(val name: String) {
|
||||
val y: String
|
||||
get() = field + "1"
|
||||
<!FIELD_IN_JVM_RECORD!>val y: String
|
||||
get() = field + "1"<!>
|
||||
|
||||
init {
|
||||
y = ""
|
||||
@@ -28,7 +28,7 @@ data class MyRec3(val name: String) {
|
||||
|
||||
@JvmRecord
|
||||
data class MyRec4(val name: String) {
|
||||
val z: Int by lazy { 1 }
|
||||
<!FIELD_IN_JVM_RECORD!>val z: Int by lazy { 1 }<!>
|
||||
}
|
||||
|
||||
@JvmRecord
|
||||
|
||||
+6
@@ -3586,4 +3586,10 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirJvmErrors.FIELD_IN_JVM_RECORD) { firDiagnostic ->
|
||||
FieldInJvmRecordImpl(
|
||||
firDiagnostic as FirPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -2497,4 +2497,8 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
override val diagnosticClass get() = InnerJvmRecord::class
|
||||
}
|
||||
|
||||
abstract class FieldInJvmRecord : KtFirDiagnostic<PsiElement>() {
|
||||
override val diagnosticClass get() = FieldInJvmRecord::class
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
@@ -4049,3 +4049,10 @@ internal class InnerJvmRecordImpl(
|
||||
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
|
||||
}
|
||||
|
||||
internal class FieldInJvmRecordImpl(
|
||||
firDiagnostic: FirPsiDiagnostic,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.FieldInJvmRecord(), KtAbstractFirDiagnostic<PsiElement> {
|
||||
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user