[K2] Support reporting of EXPECTED_CLASS_CONSTRUCTOR_PROPERTY_PARAMETER
^KT-59982 Fixed
This commit is contained in:
committed by
Space Team
parent
5623427c6d
commit
a23f2894b2
+18
@@ -11,10 +11,13 @@ import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.valOrVarKeyword
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirPrimaryConstructor
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.hasBody
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isExpect
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isInline
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.visibility
|
||||
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
||||
|
||||
@@ -39,6 +42,9 @@ object FirExpectConsistencyChecker : FirBasicDeclarationChecker() {
|
||||
getConstructorDelegationCall(declaration)?.let { delegatedConstructor ->
|
||||
reporter.reportOn(delegatedConstructor.source, FirErrors.EXPECTED_CLASS_CONSTRUCTOR_DELEGATION_CALL, context)
|
||||
}
|
||||
for (propertyParameter in getConstructorProhibitedPropertyParameters(declaration, lastClass)) {
|
||||
reporter.reportOn(propertyParameter.source, FirErrors.EXPECTED_CLASS_CONSTRUCTOR_PROPERTY_PARAMETER, context)
|
||||
}
|
||||
if (isProhibitedEnumConstructor(declaration, lastClass)) {
|
||||
reporter.reportOn(source, FirErrors.EXPECTED_ENUM_CONSTRUCTOR, context)
|
||||
}
|
||||
@@ -52,6 +58,18 @@ object FirExpectConsistencyChecker : FirBasicDeclarationChecker() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getConstructorProhibitedPropertyParameters(
|
||||
declaration: FirMemberDeclaration,
|
||||
containingClass: FirClass?,
|
||||
): List<FirValueParameter> {
|
||||
if (declaration is FirPrimaryConstructor &&
|
||||
containingClass != null && containingClass.classKind != ClassKind.ANNOTATION_CLASS && !containingClass.isInline
|
||||
) {
|
||||
return declaration.valueParameters.filter { it.source.valOrVarKeyword != null }
|
||||
}
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
private fun getConstructorDelegationCall(declaration: FirMemberDeclaration): FirDelegatedConstructorCall? {
|
||||
if (declaration is FirConstructor) {
|
||||
if (!declaration.isPrimary) {
|
||||
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
// DIAGNOSTICS: -NO_ACTUAL_FOR_EXPECT
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
expect class Foo(
|
||||
val constructorProperty: String,
|
||||
var constructorVar: String,
|
||||
constructorParameter: String,
|
||||
) {
|
||||
constructor(<!VAL_OR_VAR_ON_SECONDARY_CONSTRUCTOR_PARAMETER!>val<!> notReported: String)
|
||||
}
|
||||
|
||||
expect annotation class Ann(val s: String)
|
||||
|
||||
expect value class ValueClass(val s: String)
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// DIAGNOSTICS: -NO_ACTUAL_FOR_EXPECT
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
Reference in New Issue
Block a user