FIR checker: ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS

This commit is contained in:
Tianyu Geng
2021-08-09 08:54:56 -07:00
committed by TeamCityServer
parent 927723c766
commit 1607a8231a
16 changed files with 94 additions and 0 deletions
@@ -22366,6 +22366,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
@TestMetadata("compiler/testData/diagnostics/tests/properties")
@TestDataPath("$PROJECT_ROOT")
public class Properties {
@Test
@TestMetadata("abstarctPropertyInPrimaryConstructor.kt")
public void testAbstarctPropertyInPrimaryConstructor() throws Exception {
runTest("compiler/testData/diagnostics/tests/properties/abstarctPropertyInPrimaryConstructor.kt");
}
@Test
public void testAllFilesPresentInProperties() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/properties"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
@@ -22366,6 +22366,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
@TestMetadata("compiler/testData/diagnostics/tests/properties")
@TestDataPath("$PROJECT_ROOT")
public class Properties {
@Test
@TestMetadata("abstarctPropertyInPrimaryConstructor.kt")
public void testAbstarctPropertyInPrimaryConstructor() throws Exception {
runTest("compiler/testData/diagnostics/tests/properties/abstarctPropertyInPrimaryConstructor.kt");
}
@Test
public void testAllFilesPresentInProperties() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/properties"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
@@ -826,6 +826,7 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
parameter<ConeKotlinType>("actualType")
}
val ACCESSOR_FOR_DELEGATED_PROPERTY by error<KtPropertyAccessor>()
val ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS by error<KtModifierListOwner>(PositioningStrategy.ABSTRACT_MODIFIER)
}
val MPP_PROJECTS by object : DiagnosticGroup("Multi-platform projects") {
@@ -100,6 +100,7 @@ enum class PositioningStrategy(private val strategy: String? = null) {
ACTUAL_DECLARATION_NAME,
UNREACHABLE_CODE,
INLINE_PARAMETER_MODIFIER,
ABSTRACT_MODIFIER,
;
@@ -457,6 +457,7 @@ object FirErrors {
val WRONG_SETTER_RETURN_TYPE by error0<KtTypeReference>()
val WRONG_GETTER_RETURN_TYPE by error2<KtTypeReference, ConeKotlinType, ConeKotlinType>()
val ACCESSOR_FOR_DELEGATED_PROPERTY by error0<KtPropertyAccessor>()
val ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS by error0<KtModifierListOwner>(SourceElementPositioningStrategies.ABSTRACT_MODIFIER)
// Multi-platform projects
val EXPECTED_DECLARATION_WITH_BODY by error0<KtDeclaration>(SourceElementPositioningStrategies.DECLARATION_SIGNATURE)
@@ -57,6 +57,7 @@ object CommonDeclarationCheckers : DeclarationCheckers() {
FirInitializerTypeMismatchChecker,
FirDelegatedPropertyChecker,
FirInlinePropertyChecker,
FirPropertyFromParameterChecker,
)
override val classCheckers: Set<FirClassChecker>
@@ -0,0 +1,27 @@
/*
* 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.checkers.declaration
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.declarations.utils.isAbstract
object FirPropertyFromParameterChecker : FirPropertyChecker() {
override fun check(declaration: FirProperty, context: CheckerContext, reporter: DiagnosticReporter) {
if (declaration.source?.kind != FirFakeSourceElementKind.PropertyFromParameter) return
if (declaration.isAbstract) {
reporter.reportOn(
declaration.source,
FirErrors.ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS,
context
)
}
}
}
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ABSTRACT_FUNCTION
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ABSTRACT_FUNCTION_WITH_BODY
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ABSTRACT_MEMBER_NOT_IMPLEMENTED
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ABSTRACT_PROPERTY_WITH_GETTER
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ABSTRACT_PROPERTY_WITH_INITIALIZER
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ABSTRACT_PROPERTY_WITH_SETTER
@@ -1217,6 +1218,7 @@ class FirDefaultErrorMessages {
RENDER_TYPE
)
map.put(ACCESSOR_FOR_DELEGATED_PROPERTY, "Delegated property cannot have accessors with non-default implementations")
map.put(ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS, "This property cannot be declared abstract")
map.put(CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT, "Const 'val' are only allowed on top level or in objects")
map.put(CONST_VAL_WITH_GETTER, "Const 'val' should not have a getter")
@@ -0,0 +1,2 @@
class A(<!ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS!>abstract<!> val i: Int)
class B(abstract i: Int)
@@ -0,0 +1,2 @@
class A(<!ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS!>abstract<!> val i: Int)
class B(<!WRONG_MODIFIER_TARGET!>abstract<!> i: Int)
@@ -0,0 +1,16 @@
package
public final class A {
public constructor A(/*0*/ i: kotlin.Int)
public abstract val i: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class B {
public constructor B(/*0*/ i: kotlin.Int)
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -22372,6 +22372,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
@TestMetadata("compiler/testData/diagnostics/tests/properties")
@TestDataPath("$PROJECT_ROOT")
public class Properties {
@Test
@TestMetadata("abstarctPropertyInPrimaryConstructor.kt")
public void testAbstarctPropertyInPrimaryConstructor() throws Exception {
runTest("compiler/testData/diagnostics/tests/properties/abstarctPropertyInPrimaryConstructor.kt");
}
@Test
public void testAllFilesPresentInProperties() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/properties"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
@@ -22366,6 +22366,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
@TestMetadata("compiler/testData/diagnostics/tests/properties")
@TestDataPath("$PROJECT_ROOT")
public class Properties {
@Test
@TestMetadata("abstarctPropertyInPrimaryConstructor.kt")
public void testAbstarctPropertyInPrimaryConstructor() throws Exception {
runTest("compiler/testData/diagnostics/tests/properties/abstarctPropertyInPrimaryConstructor.kt");
}
@Test
public void testAllFilesPresentInProperties() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/properties"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
@@ -2271,6 +2271,12 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirErrors.ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS) { firDiagnostic ->
AbstractPropertyInPrimaryConstructorParametersImpl(
firDiagnostic as FirPsiDiagnostic,
token,
)
}
add(FirErrors.EXPECTED_DECLARATION_WITH_BODY) { firDiagnostic ->
ExpectedDeclarationWithBodyImpl(
firDiagnostic as FirPsiDiagnostic,
@@ -1608,6 +1608,10 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
override val diagnosticClass get() = AccessorForDelegatedProperty::class
}
abstract class AbstractPropertyInPrimaryConstructorParameters : KtFirDiagnostic<KtModifierListOwner>() {
override val diagnosticClass get() = AbstractPropertyInPrimaryConstructorParameters::class
}
abstract class ExpectedDeclarationWithBody : KtFirDiagnostic<KtDeclaration>() {
override val diagnosticClass get() = ExpectedDeclarationWithBody::class
}
@@ -2587,6 +2587,13 @@ internal class AccessorForDelegatedPropertyImpl(
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
}
internal class AbstractPropertyInPrimaryConstructorParametersImpl(
firDiagnostic: FirPsiDiagnostic,
override val token: ValidityToken,
) : KtFirDiagnostic.AbstractPropertyInPrimaryConstructorParameters(), KtAbstractFirDiagnostic<KtModifierListOwner> {
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
}
internal class ExpectedDeclarationWithBodyImpl(
firDiagnostic: FirPsiDiagnostic,
override val token: ValidityToken,