[K2] Support reporting of EXPECTED_ENUM_CONSTRUCTOR
^KT-59980 Fixed
This commit is contained in:
committed by
Space Team
parent
6112c4ab2c
commit
489371219f
+8
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
@@ -38,6 +39,9 @@ object FirExpectConsistencyChecker : FirBasicDeclarationChecker() {
|
||||
getConstructorDelegationCall(declaration)?.let { delegatedConstructor ->
|
||||
reporter.reportOn(delegatedConstructor.source, FirErrors.EXPECTED_CLASS_CONSTRUCTOR_DELEGATION_CALL, context)
|
||||
}
|
||||
if (isProhibitedEnumConstructor(declaration, lastClass)) {
|
||||
reporter.reportOn(source, FirErrors.EXPECTED_ENUM_CONSTRUCTOR, context)
|
||||
}
|
||||
|
||||
if (isProhibitedPrivateDeclaration(declaration)) {
|
||||
reporter.reportOn(source, FirErrors.EXPECTED_PRIVATE_DECLARATION, context)
|
||||
@@ -65,6 +69,10 @@ object FirExpectConsistencyChecker : FirBasicDeclarationChecker() {
|
||||
return declaration !is FirConstructor && declaration !is FirPropertyAccessor && Visibilities.isPrivate(declaration.visibility)
|
||||
}
|
||||
|
||||
private fun isProhibitedEnumConstructor(declaration: FirMemberDeclaration, lastClass: FirClass?): Boolean {
|
||||
return declaration is FirConstructor && lastClass?.classKind == ClassKind.ENUM_CLASS
|
||||
}
|
||||
|
||||
private fun isProhibitedDeclarationWithBody(declaration: FirMemberDeclaration): Boolean {
|
||||
return declaration is FirFunction && declaration.hasBody
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
<!NO_ACTUAL_FOR_EXPECT!>expect enum class En(x: Int) {
|
||||
<!NO_ACTUAL_FOR_EXPECT!>expect enum class En<!EXPECTED_ENUM_CONSTRUCTOR!>(x: Int)<!> {
|
||||
E1,
|
||||
E2(42),
|
||||
;
|
||||
|
||||
constructor(s: String)
|
||||
<!EXPECTED_ENUM_CONSTRUCTOR!>constructor(s: String)<!>
|
||||
}<!>
|
||||
|
||||
<!NO_ACTUAL_FOR_EXPECT!>expect enum class En2 {
|
||||
|
||||
Reference in New Issue
Block a user