[FIR] Only one specific diagnostic for data class without parameters left
^KT-60042 fixed
This commit is contained in:
committed by
Space Team
parent
17dc60aac9
commit
3673dff959
-7
@@ -46,7 +46,6 @@ import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.psi.KtPrimaryConstructor
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
import org.jetbrains.kotlin.psi.KtPropertyAccessor
|
||||
import org.jetbrains.kotlin.psi.KtReturnExpression
|
||||
@@ -824,12 +823,6 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS) { firDiagnostic ->
|
||||
PrimaryConstructorRequiredForDataClassImpl(
|
||||
firDiagnostic as KtPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.EXPLICIT_DELEGATION_CALL_REQUIRED) { firDiagnostic ->
|
||||
ExplicitDelegationCallRequiredImpl(
|
||||
firDiagnostic as KtPsiDiagnostic,
|
||||
|
||||
+1
-6
@@ -65,7 +65,6 @@ import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.psi.KtPrimaryConstructor
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
import org.jetbrains.kotlin.psi.KtPropertyAccessor
|
||||
import org.jetbrains.kotlin.psi.KtReturnExpression
|
||||
@@ -616,10 +615,6 @@ sealed interface KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
override val diagnosticClass get() = DelegationSuperCallInEnumConstructor::class
|
||||
}
|
||||
|
||||
interface PrimaryConstructorRequiredForDataClass : KtFirDiagnostic<KtNamedDeclaration> {
|
||||
override val diagnosticClass get() = PrimaryConstructorRequiredForDataClass::class
|
||||
}
|
||||
|
||||
interface ExplicitDelegationCallRequired : KtFirDiagnostic<PsiElement> {
|
||||
override val diagnosticClass get() = ExplicitDelegationCallRequired::class
|
||||
}
|
||||
@@ -628,7 +623,7 @@ sealed interface KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
override val diagnosticClass get() = SealedClassConstructorCall::class
|
||||
}
|
||||
|
||||
interface DataClassWithoutParameters : KtFirDiagnostic<KtPrimaryConstructor> {
|
||||
interface DataClassWithoutParameters : KtFirDiagnostic<KtNamedDeclaration> {
|
||||
override val diagnosticClass get() = DataClassWithoutParameters::class
|
||||
}
|
||||
|
||||
|
||||
+1
-7
@@ -66,7 +66,6 @@ import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.psi.KtPrimaryConstructor
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
import org.jetbrains.kotlin.psi.KtPropertyAccessor
|
||||
import org.jetbrains.kotlin.psi.KtReturnExpression
|
||||
@@ -728,11 +727,6 @@ internal class DelegationSuperCallInEnumConstructorImpl(
|
||||
token: KtLifetimeToken,
|
||||
) : KtAbstractFirDiagnostic<PsiElement>(firDiagnostic, token), KtFirDiagnostic.DelegationSuperCallInEnumConstructor
|
||||
|
||||
internal class PrimaryConstructorRequiredForDataClassImpl(
|
||||
firDiagnostic: KtPsiDiagnostic,
|
||||
token: KtLifetimeToken,
|
||||
) : KtAbstractFirDiagnostic<KtNamedDeclaration>(firDiagnostic, token), KtFirDiagnostic.PrimaryConstructorRequiredForDataClass
|
||||
|
||||
internal class ExplicitDelegationCallRequiredImpl(
|
||||
firDiagnostic: KtPsiDiagnostic,
|
||||
token: KtLifetimeToken,
|
||||
@@ -746,7 +740,7 @@ internal class SealedClassConstructorCallImpl(
|
||||
internal class DataClassWithoutParametersImpl(
|
||||
firDiagnostic: KtPsiDiagnostic,
|
||||
token: KtLifetimeToken,
|
||||
) : KtAbstractFirDiagnostic<KtPrimaryConstructor>(firDiagnostic, token), KtFirDiagnostic.DataClassWithoutParameters
|
||||
) : KtAbstractFirDiagnostic<KtNamedDeclaration>(firDiagnostic, token), KtFirDiagnostic.DataClassWithoutParameters
|
||||
|
||||
internal class DataClassVarargParameterImpl(
|
||||
firDiagnostic: KtPsiDiagnostic,
|
||||
|
||||
Vendored
+3
-3
@@ -1,9 +1,9 @@
|
||||
data <!PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS!>class A<!> {}
|
||||
data <!DATA_CLASS_WITHOUT_PARAMETERS!>class A<!> {}
|
||||
|
||||
data <!PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS!>class B<!> {
|
||||
data <!DATA_CLASS_WITHOUT_PARAMETERS!>class B<!> {
|
||||
constructor()
|
||||
}
|
||||
|
||||
data <!PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS!>class C<!> {
|
||||
data <!DATA_CLASS_WITHOUT_PARAMETERS!>class C<!> {
|
||||
constructor(x: Int)
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
private sealed class Sealed
|
||||
|
||||
private data class SubClass1(val t: String) : Sealed()
|
||||
private data <!PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS!>class SubClass2<!> : Sealed()
|
||||
private data <!DATA_CLASS_WITHOUT_PARAMETERS!>class SubClass2<!> : Sealed()
|
||||
|
||||
private fun foo(p: Sealed) {
|
||||
when (p) {
|
||||
|
||||
+1
-2
@@ -307,12 +307,11 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
|
||||
val SUPERTYPE_NOT_INITIALIZED by error<KtTypeReference>()
|
||||
val SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR by error<PsiElement>()
|
||||
val DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR by error<PsiElement>()
|
||||
val PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS by error<KtNamedDeclaration>(PositioningStrategy.DECLARATION_NAME)
|
||||
val EXPLICIT_DELEGATION_CALL_REQUIRED by error<PsiElement>(PositioningStrategy.SECONDARY_CONSTRUCTOR_DELEGATION_CALL)
|
||||
val SEALED_CLASS_CONSTRUCTOR_CALL by error<PsiElement>()
|
||||
|
||||
// TODO: Consider creating a parameter list position strategy and report on the parameter list instead
|
||||
val DATA_CLASS_WITHOUT_PARAMETERS by error<KtPrimaryConstructor>()
|
||||
val DATA_CLASS_WITHOUT_PARAMETERS by error<KtNamedDeclaration>(PositioningStrategy.DECLARATION_NAME)
|
||||
val DATA_CLASS_VARARG_PARAMETER by error<KtParameter>()
|
||||
val DATA_CLASS_NOT_PROPERTY_PARAMETER by error<KtParameter>()
|
||||
}
|
||||
|
||||
+1
-3
@@ -91,7 +91,6 @@ import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.psi.KtPrimaryConstructor
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
import org.jetbrains.kotlin.psi.KtPropertyAccessor
|
||||
import org.jetbrains.kotlin.psi.KtReturnExpression
|
||||
@@ -245,10 +244,9 @@ object FirErrors {
|
||||
val SUPERTYPE_NOT_INITIALIZED by error0<KtTypeReference>()
|
||||
val SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR by error0<PsiElement>()
|
||||
val DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR by error0<PsiElement>()
|
||||
val PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS by error0<KtNamedDeclaration>(SourceElementPositioningStrategies.DECLARATION_NAME)
|
||||
val EXPLICIT_DELEGATION_CALL_REQUIRED by error0<PsiElement>(SourceElementPositioningStrategies.SECONDARY_CONSTRUCTOR_DELEGATION_CALL)
|
||||
val SEALED_CLASS_CONSTRUCTOR_CALL by error0<PsiElement>()
|
||||
val DATA_CLASS_WITHOUT_PARAMETERS by error0<KtPrimaryConstructor>()
|
||||
val DATA_CLASS_WITHOUT_PARAMETERS by error0<KtNamedDeclaration>(SourceElementPositioningStrategies.DECLARATION_NAME)
|
||||
val DATA_CLASS_VARARG_PARAMETER by error0<KtParameter>()
|
||||
val DATA_CLASS_NOT_PROPERTY_PARAMETER by error0<KtParameter>()
|
||||
|
||||
|
||||
-1
@@ -112,7 +112,6 @@ val FIR_NON_SUPPRESSIBLE_ERROR_NAMES: Set<String> = setOf(
|
||||
"SUPERTYPE_NOT_INITIALIZED",
|
||||
"SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR",
|
||||
"DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR",
|
||||
"PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS",
|
||||
"EXPLICIT_DELEGATION_CALL_REQUIRED",
|
||||
"SEALED_CLASS_CONSTRUCTOR_CALL",
|
||||
"DATA_CLASS_WITHOUT_PARAMETERS",
|
||||
|
||||
+2
-3
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.hasValOrVar
|
||||
@@ -24,8 +23,8 @@ object FirDataClassPrimaryConstructorChecker : FirRegularClassChecker() {
|
||||
|
||||
val primaryConstructor = declaration.primaryConstructorIfAny(context.session)
|
||||
|
||||
if (primaryConstructor == null || primaryConstructor.source.let { it == null || it.kind is KtFakeSourceElementKind }) {
|
||||
reporter.reportOn(declaration.source, FirErrors.PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS, context)
|
||||
if (primaryConstructor?.source == null) {
|
||||
reporter.reportOn(declaration.source, FirErrors.DATA_CLASS_WITHOUT_PARAMETERS, context)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
-2
@@ -496,7 +496,6 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PLUGIN_ANNOTATION
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.POTENTIALLY_NON_REPORTED_ANNOTATION
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PRE_RELEASE_CLASS
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PRIVATE_CLASS_MEMBER_FROM_INLINE
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PRIVATE_FUNCTION_WITH_NO_BODY
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PRIVATE_PROPERTY_IN_INTERFACE
|
||||
@@ -943,7 +942,6 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
|
||||
map.put(PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL, "Protected constructor ''{0}'' from other classes can only be used in super-call.", SYMBOL)
|
||||
map.put(SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR, "Supertype initialization is impossible without a primary constructor.")
|
||||
map.put(DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR, "Calls to super in enum constructors are prohibited.")
|
||||
map.put(PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS, "Primary constructor required for data class.")
|
||||
map.put(
|
||||
EXPLICIT_DELEGATION_CALL_REQUIRED,
|
||||
"Explicit 'this' or 'super' call is required. There is no constructor in the superclass that can be called without arguments."
|
||||
|
||||
+1
@@ -238,6 +238,7 @@ object LightTreePositioningStrategies {
|
||||
//in FE 1.0 this is part of DeclarationHeader abstract strategy
|
||||
if (node.tokenType != KtNodeTypes.OBJECT_DECLARATION
|
||||
&& node.tokenType != KtNodeTypes.FUN
|
||||
&& node.tokenType != KtNodeTypes.PRIMARY_CONSTRUCTOR
|
||||
&& node.tokenType != KtNodeTypes.SECONDARY_CONSTRUCTOR
|
||||
&& node.tokenType != KtNodeTypes.OBJECT_LITERAL
|
||||
) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
data <!PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS!>class A<!>
|
||||
data <!DATA_CLASS_WITHOUT_PARAMETERS!>class A<!>
|
||||
|
||||
fun foo(a: A) {
|
||||
a.<!UNRESOLVED_REFERENCE!>component1<!>()
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ data class A2(val y: String, val z: Int) {
|
||||
constructor(x: String): this(x, 0)
|
||||
}
|
||||
|
||||
data <!PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS!>class A3<!> {
|
||||
data <!DATA_CLASS_WITHOUT_PARAMETERS!>class A3<!> {
|
||||
constructor()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user