From 6618b4ea57f89f41e1d94f75f60746ef4cf89b10 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 7 May 2021 12:28:56 +0300 Subject: [PATCH] FirPropertyAccessorChecker: add three new diagnostics --- .../diagnostics/FirDiagnosticsList.kt | 6 +++ .../fir/analysis/diagnostics/FirErrors.kt | 3 ++ .../declaration/FirPropertyAccessorChecker.kt | 43 ++++++++++++++++++- .../diagnostics/FirDefaultErrorMessages.kt | 11 +++++ .../tests/OverridenSetterVisibility.fir.kt | 2 +- .../diagnostics/tests/SetterVisibility.fir.kt | 25 ----------- .../diagnostics/tests/SetterVisibility.kt | 1 + .../nonDefaultAccessors.fir.kt | 12 ------ .../delegatedProperty/nonDefaultAccessors.kt | 1 + .../delegatedProperty/redundantGetter.fir.kt | 12 ------ .../delegatedProperty/redundantGetter.kt | 1 + .../delegatedProperty/redundantSetter.fir.kt | 15 ------- .../delegatedProperty/redundantSetter.kt | 1 + .../diagnostics/tests/lateinit/setter.fir.kt | 22 ---------- .../diagnostics/tests/lateinit/setter.kt | 1 + .../tests/regressions/kt251.fir.kt | 6 +-- .../PropertyDelegateWithPrivateSet.fir.kt | 2 +- .../jvmStatic/interfaceCompanion_LL12.fir.kt | 2 +- .../interfaceCompanion_LL13_16.fir.kt | 2 +- .../interfaceCompanion_LL13_18.fir.kt | 2 +- .../diagnostics/KtFirDataClassConverters.kt | 20 +++++++++ .../api/fir/diagnostics/KtFirDiagnostics.kt | 14 ++++++ .../fir/diagnostics/KtFirDiagnosticsImpl.kt | 23 ++++++++++ 23 files changed, 131 insertions(+), 96 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/SetterVisibility.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/nonDefaultAccessors.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/redundantGetter.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/delegatedProperty/redundantSetter.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/lateinit/setter.fir.kt diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt index 74379992d27..66fbd6faa83 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt @@ -578,7 +578,13 @@ object DIAGNOSTICS_LIST : DiagnosticList() { parameter("actual") } val GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY by error(PositioningStrategy.VISIBILITY_MODIFIER) + val SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY by error(PositioningStrategy.VISIBILITY_MODIFIER) val WRONG_SETTER_RETURN_TYPE by error() + val WRONG_GETTER_RETURN_TYPE by error { + parameter("expectedType") + parameter("actualType") + } + val ACCESSOR_FOR_DELEGATED_PROPERTY by error() } val MPP_PROJECTS by object : DiagnosticGroup("Multi-platform projects") { diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index fb931d76616..54f11de9fa9 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -360,7 +360,10 @@ object FirErrors { val WRONG_SETTER_PARAMETER_TYPE by error2() val INITIALIZER_TYPE_MISMATCH by error2(SourceElementPositioningStrategies.ASSIGNMENT_VALUE) val GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY by error0(SourceElementPositioningStrategies.VISIBILITY_MODIFIER) + val SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY by error0(SourceElementPositioningStrategies.VISIBILITY_MODIFIER) val WRONG_SETTER_RETURN_TYPE by error0() + val WRONG_GETTER_RETURN_TYPE by error2() + val ACCESSOR_FOR_DELEGATED_PROPERTY by error0() // Multi-platform projects val EXPECTED_DECLARATION_WITH_BODY by error0(SourceElementPositioningStrategies.DECLARATION_SIGNATURE) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPropertyAccessorChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPropertyAccessorChecker.kt index 27866e5982f..798a411f3c2 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPropertyAccessorChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirPropertyAccessorChecker.kt @@ -5,12 +5,14 @@ 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.analysis.diagnostics.withSuppressedDiagnostics import org.jetbrains.kotlin.fir.declarations.FirProperty +import org.jetbrains.kotlin.fir.declarations.FirPropertyAccessor import org.jetbrains.kotlin.fir.declarations.visibility import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.coneType @@ -24,20 +26,43 @@ object FirPropertyAccessorChecker : FirPropertyChecker() { private fun checkGetter(property: FirProperty, context: CheckerContext, reporter: DiagnosticReporter) { val getter = property.getter ?: return + val propertyType = property.returnTypeRef.coneType + withSuppressedDiagnostics(getter, context) { + checkAccessorForDelegatedProperty(property, getter, context, reporter) if (getter.visibility != property.visibility) { reporter.reportOn(getter.source, FirErrors.GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, context) } + val getterReturnTypeRef = getter.returnTypeRef + if (getterReturnTypeRef.source?.kind is FirFakeSourceElementKind) { + return + } + val getterReturnType = getterReturnTypeRef.coneType + if (propertyType is ConeClassErrorType || getterReturnType is ConeClassErrorType) { + return + } + if (getterReturnType != property.returnTypeRef.coneType) { + val getterReturnTypeSource = getterReturnTypeRef.source + withSuppressedDiagnostics(getterReturnTypeRef, context) { + reporter.reportOn(getterReturnTypeSource, FirErrors.WRONG_GETTER_RETURN_TYPE, propertyType, getterReturnType, context) + } + } } } private fun checkSetter(property: FirProperty, context: CheckerContext, reporter: DiagnosticReporter) { val setter = property.setter ?: return + val propertyType = property.returnTypeRef.coneType withSuppressedDiagnostics(setter, context) { if (property.isVal) { reporter.reportOn(setter.source, FirErrors.VAL_WITH_SETTER, context) } + checkAccessorForDelegatedProperty(property, setter, context, reporter) + val visibilityCompareResult = setter.visibility.compareTo(property.visibility) + if (visibilityCompareResult == null || visibilityCompareResult > 0) { + reporter.reportOn(setter.source, FirErrors.SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY, context) + } val valueSetterParameter = setter.valueParameters.first() if (valueSetterParameter.isVararg) { @@ -45,7 +70,6 @@ object FirPropertyAccessorChecker : FirPropertyChecker() { } val valueSetterType = valueSetterParameter.returnTypeRef.coneType val valueSetterTypeSource = valueSetterParameter.returnTypeRef.source - val propertyType = property.returnTypeRef.coneType if (propertyType is ConeClassErrorType || valueSetterType is ConeClassErrorType) { return } @@ -62,8 +86,23 @@ object FirPropertyAccessorChecker : FirPropertyChecker() { } if (!setterReturnType.isUnit) { - reporter.reportOn(setter.returnTypeRef.source, FirErrors.WRONG_SETTER_RETURN_TYPE, context) + withSuppressedDiagnostics(setter.returnTypeRef, context) { + reporter.reportOn(setter.returnTypeRef.source, FirErrors.WRONG_SETTER_RETURN_TYPE, context) + } } } } + + private fun checkAccessorForDelegatedProperty( + property: FirProperty, + accessor: FirPropertyAccessor, + context: CheckerContext, + reporter: DiagnosticReporter + ) { + if (property.delegateFieldSymbol != null && accessor.body != null && + accessor.source?.kind != FirFakeSourceElementKind.DelegatedPropertyAccessor + ) { + reporter.reportOn(accessor.source, FirErrors.ACCESSOR_FOR_DELEGATED_PROPERTY, context) + } + } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt index 91570fa5501..83ddb364001 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ABSTRACT_PROPERTY import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ABSTRACT_PROPERTY_WITH_INITIALIZER import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ABSTRACT_PROPERTY_WITH_SETTER import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ABSTRACT_SUPER_CALL +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ACCESSOR_FOR_DELEGATED_PROPERTY import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ANNOTATION_ARGUMENT_MUST_BE_CONST import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ANNOTATION_CLASS_MEMBER import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ANNOTATION_PARAMETER_DEFAULT_VALUE_MUST_BE_CONSTANT @@ -252,6 +253,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SEALED_CLASS_CONS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SEALED_SUPERTYPE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SEALED_SUPERTYPE_IN_LOCAL_CLASS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_INLINE_CLASS +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SUPERCLASS_NOT_ACCESSIBLE_FROM_INTERFACE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SUPERTYPES_FOR_ANNOTATION_CLASS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SUPERTYPE_INITIALIZED_IN_INTERFACE @@ -314,6 +316,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.VARIANCE_ON_TYPE_ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.VAR_ANNOTATION_PARAMETER import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.VAR_OVERRIDDEN_BY_VAL import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.VAR_TYPE_MISMATCH_ON_OVERRIDE +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.WRONG_GETTER_RETURN_TYPE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.WRONG_INVOCATION_KIND import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.WRONG_MODIFIER_TARGET import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.WRONG_NUMBER_OF_TYPE_ARGUMENTS @@ -819,7 +822,15 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension { ) map.put(INITIALIZER_TYPE_MISMATCH, "Initializer type mismatch: expected {0}, actual {1}", RENDER_TYPE, RENDER_TYPE) map.put(GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, "Getter visibility must be the same as property visibility") + map.put(SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY, "Setter visibility must be the same or less permissive than property visibility") map.put(WRONG_SETTER_RETURN_TYPE, "Setter return type must be Unit") + map.put( + WRONG_GETTER_RETURN_TYPE, + "Getter return type must be equal to the type of the property, i.e. ''{0}''", + RENDER_TYPE, + RENDER_TYPE + ) + map.put(ACCESSOR_FOR_DELEGATED_PROPERTY, "Delegated property cannot have accessors with non-default implementations") 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") diff --git a/compiler/testData/diagnostics/tests/OverridenSetterVisibility.fir.kt b/compiler/testData/diagnostics/tests/OverridenSetterVisibility.fir.kt index cbae506efc4..53033533d59 100644 --- a/compiler/testData/diagnostics/tests/OverridenSetterVisibility.fir.kt +++ b/compiler/testData/diagnostics/tests/OverridenSetterVisibility.fir.kt @@ -17,7 +17,7 @@ class Test: ATest(), ITest { override var prop2 : Int get() = 14 - internal set(value) {} + internal set(value) {} } fun main() { diff --git a/compiler/testData/diagnostics/tests/SetterVisibility.fir.kt b/compiler/testData/diagnostics/tests/SetterVisibility.fir.kt deleted file mode 100644 index 35e921407f3..00000000000 --- a/compiler/testData/diagnostics/tests/SetterVisibility.fir.kt +++ /dev/null @@ -1,25 +0,0 @@ -class My { - var x: Int = 0 - // Ok - private set - - private var y: Int = 1 - // Error: better - public set - - protected var z: Int = 2 - // Ok - private set - - protected var w: Int = 3 - // Error: incompatible - internal set - - internal var v: Int = 4 - // Error: incompatible - protected set - - internal var t: Int = 5 - // Error: better - public set -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/SetterVisibility.kt b/compiler/testData/diagnostics/tests/SetterVisibility.kt index 6e3a44cff8e..37be8571800 100644 --- a/compiler/testData/diagnostics/tests/SetterVisibility.kt +++ b/compiler/testData/diagnostics/tests/SetterVisibility.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL class My { var x: Int = 0 // Ok diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/nonDefaultAccessors.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/nonDefaultAccessors.fir.kt deleted file mode 100644 index bc1fa1e3ab4..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/nonDefaultAccessors.fir.kt +++ /dev/null @@ -1,12 +0,0 @@ -// KT-11809 Assertion error when delegated property has getter - -class A { - val p1 by this - get - - var p2 by this - get() = "" - - operator fun getValue(a: Any?, p: Any?) = "" - operator fun setValue(a: Any?, p: Any?, v: Any?) {} -} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/nonDefaultAccessors.kt b/compiler/testData/diagnostics/tests/delegatedProperty/nonDefaultAccessors.kt index a3d8233880b..5708e28d291 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/nonDefaultAccessors.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/nonDefaultAccessors.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // KT-11809 Assertion error when delegated property has getter class A { diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/redundantGetter.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/redundantGetter.fir.kt deleted file mode 100644 index 3749eb07218..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/redundantGetter.fir.kt +++ /dev/null @@ -1,12 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -import kotlin.reflect.KProperty - -val a: Int by Delegate() - get() = 1 - -class Delegate { - operator fun getValue(t: Any?, p: KProperty<*>): Int { - return 1 - } -} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/redundantGetter.kt b/compiler/testData/diagnostics/tests/delegatedProperty/redundantGetter.kt index 2882c88d6ca..0cb1bb6115d 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/redundantGetter.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/redundantGetter.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER import kotlin.reflect.KProperty diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/redundantSetter.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/redundantSetter.fir.kt deleted file mode 100644 index a7009e50fa9..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/redundantSetter.fir.kt +++ /dev/null @@ -1,15 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -import kotlin.reflect.KProperty - -var a: Int by Delegate() - get() = 1 - set(i) {} - -class Delegate { - operator fun getValue(t: Any?, p: KProperty<*>): Int { - return 1 - } - - operator fun setValue(t: Any?, p: KProperty<*>, i: Int) {} -} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/redundantSetter.kt b/compiler/testData/diagnostics/tests/delegatedProperty/redundantSetter.kt index a9926a8a113..20835e1be09 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/redundantSetter.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/redundantSetter.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER import kotlin.reflect.KProperty diff --git a/compiler/testData/diagnostics/tests/lateinit/setter.fir.kt b/compiler/testData/diagnostics/tests/lateinit/setter.fir.kt deleted file mode 100644 index 18d914f0725..00000000000 --- a/compiler/testData/diagnostics/tests/lateinit/setter.fir.kt +++ /dev/null @@ -1,22 +0,0 @@ -class My { - - lateinit var x: String - private set - - lateinit var y: String - internal set - - lateinit protected var z: String - private set - - lateinit private var w: String - // Ok, private var / private set - private set - - lateinit protected var v: String - public set - - lateinit public var u: String - // Ok, public var / public set - public set -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/lateinit/setter.kt b/compiler/testData/diagnostics/tests/lateinit/setter.kt index b533370f204..69a5eb50f82 100644 --- a/compiler/testData/diagnostics/tests/lateinit/setter.kt +++ b/compiler/testData/diagnostics/tests/lateinit/setter.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL class My { lateinit var x: String diff --git a/compiler/testData/diagnostics/tests/regressions/kt251.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt251.fir.kt index f2d93703c93..280a3680e48 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt251.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt251.fir.kt @@ -6,7 +6,7 @@ class A() { field = value } val y: Int - get(): String = "s" + get(): String = "s" val z: Int get() { return "s" @@ -17,7 +17,7 @@ class A() { field = v } val b: Int - get(): Any = "s" + get(): Any = "s" val c: Int get() { return 1 @@ -27,7 +27,7 @@ class A() { return field } val e = 1 - get(): String { + get(): String { return field } diff --git a/compiler/testData/diagnostics/testsWithStdLib/PropertyDelegateWithPrivateSet.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/PropertyDelegateWithPrivateSet.fir.kt index 40ccffe49e1..23854dbad09 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/PropertyDelegateWithPrivateSet.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/PropertyDelegateWithPrivateSet.fir.kt @@ -8,5 +8,5 @@ class My { val another: String = delegate var delegateWithBackingField: String by kotlin.properties.Delegates.notNull() - private set(arg) { field = arg } + private set(arg) { field = arg } } diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL12.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL12.fir.kt index 7f69d354701..a62b3c83176 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL12.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL12.fir.kt @@ -45,7 +45,7 @@ interface B { @JvmStatic get private var foo8 = 1 - @JvmStatic public set + @JvmStatic public set public var foo9 = 1 @JvmStatic private set diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_16.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_16.fir.kt index be8b42471bc..20754cb4c63 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_16.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_16.fir.kt @@ -47,7 +47,7 @@ interface B { @JvmStatic get private var foo8 = 1 - @JvmStatic public set + @JvmStatic public set public var foo9 = 1 @JvmStatic private set diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_18.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_18.fir.kt index aafae7e4f93..0d49e751ca8 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_18.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_18.fir.kt @@ -46,7 +46,7 @@ interface B { @JvmStatic get private var foo8 = 1 - @JvmStatic public set + @JvmStatic public set public var foo9 = 1 @JvmStatic private set diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt index 0bfaee736b7..594585eba94 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt @@ -1696,12 +1696,32 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert token, ) } + add(FirErrors.SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY) { firDiagnostic -> + SetterVisibilityInconsistentWithPropertyVisibilityImpl( + firDiagnostic as FirPsiDiagnostic<*>, + token, + ) + } add(FirErrors.WRONG_SETTER_RETURN_TYPE) { firDiagnostic -> WrongSetterReturnTypeImpl( firDiagnostic as FirPsiDiagnostic<*>, token, ) } + add(FirErrors.WRONG_GETTER_RETURN_TYPE) { firDiagnostic -> + WrongGetterReturnTypeImpl( + firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a), + firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.b), + firDiagnostic as FirPsiDiagnostic<*>, + token, + ) + } + add(FirErrors.ACCESSOR_FOR_DELEGATED_PROPERTY) { firDiagnostic -> + AccessorForDelegatedPropertyImpl( + firDiagnostic as FirPsiDiagnostic<*>, + token, + ) + } add(FirErrors.EXPECTED_DECLARATION_WITH_BODY) { firDiagnostic -> ExpectedDeclarationWithBodyImpl( firDiagnostic as FirPsiDiagnostic<*>, diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt index 2ae1a492407..a425eacc5dd 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt @@ -1191,10 +1191,24 @@ sealed class KtFirDiagnostic : KtDiagnosticWithPsi { override val diagnosticClass get() = GetterVisibilityDiffersFromPropertyVisibility::class } + abstract class SetterVisibilityInconsistentWithPropertyVisibility : KtFirDiagnostic() { + override val diagnosticClass get() = SetterVisibilityInconsistentWithPropertyVisibility::class + } + abstract class WrongSetterReturnType : KtFirDiagnostic() { override val diagnosticClass get() = WrongSetterReturnType::class } + abstract class WrongGetterReturnType : KtFirDiagnostic() { + override val diagnosticClass get() = WrongGetterReturnType::class + abstract val expectedType: KtType + abstract val actualType: KtType + } + + abstract class AccessorForDelegatedProperty : KtFirDiagnostic() { + override val diagnosticClass get() = AccessorForDelegatedProperty::class + } + abstract class ExpectedDeclarationWithBody : KtFirDiagnostic() { override val diagnosticClass get() = ExpectedDeclarationWithBody::class } diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt index 9bb5a4fcb6d..1a733699474 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt @@ -1936,6 +1936,13 @@ internal class GetterVisibilityDiffersFromPropertyVisibilityImpl( override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) } +internal class SetterVisibilityInconsistentWithPropertyVisibilityImpl( + firDiagnostic: FirPsiDiagnostic<*>, + override val token: ValidityToken, +) : KtFirDiagnostic.SetterVisibilityInconsistentWithPropertyVisibility(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) +} + internal class WrongSetterReturnTypeImpl( firDiagnostic: FirPsiDiagnostic<*>, override val token: ValidityToken, @@ -1943,6 +1950,22 @@ internal class WrongSetterReturnTypeImpl( override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) } +internal class WrongGetterReturnTypeImpl( + override val expectedType: KtType, + override val actualType: KtType, + firDiagnostic: FirPsiDiagnostic<*>, + override val token: ValidityToken, +) : KtFirDiagnostic.WrongGetterReturnType(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) +} + +internal class AccessorForDelegatedPropertyImpl( + firDiagnostic: FirPsiDiagnostic<*>, + override val token: ValidityToken, +) : KtFirDiagnostic.AccessorForDelegatedProperty(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) +} + internal class ExpectedDeclarationWithBodyImpl( firDiagnostic: FirPsiDiagnostic<*>, override val token: ValidityToken,