[FIR] Report EXPECTED_CLASS_CONSTRUCTOR_DELEGATION_CALL

^KT-59069 Fixed
This commit is contained in:
Ivan Kochurkin
2023-07-18 22:15:00 +02:00
committed by Space Team
parent f7269eb384
commit 8f4a580c17
3 changed files with 14 additions and 5 deletions
@@ -25,8 +25,7 @@ object FirExpectConsistencyChecker : FirBasicDeclarationChecker() {
if (
declaration !is FirMemberDeclaration ||
!isTopLevel && !isInsideClass ||
!declaration.isExpect ||
declaration is FirConstructor
!declaration.isExpect
) {
return
}
@@ -34,6 +33,16 @@ object FirExpectConsistencyChecker : FirBasicDeclarationChecker() {
val source = declaration.source ?: return
if (source.kind is KtFakeSourceElementKind) return
if (declaration is FirConstructor) {
if (!declaration.isPrimary) {
val delegatedConstructorSource = declaration.delegatedConstructor?.source
if (delegatedConstructorSource?.kind !is KtFakeSourceElementKind) {
reporter.reportOn(delegatedConstructorSource, FirErrors.EXPECTED_CLASS_CONSTRUCTOR_DELEGATION_CALL, context)
}
}
return
}
if (Visibilities.isPrivate(declaration.visibility)) {
reporter.reportOn(source, FirErrors.EXPECTED_PRIVATE_DECLARATION, context)
}
@@ -3,11 +3,11 @@
<!NO_ACTUAL_FOR_EXPECT!>expect open class A {
constructor(s: String)
constructor(n: Number) : this("A")
constructor(n: Number) : <!EXPECTED_CLASS_CONSTRUCTOR_DELEGATION_CALL!>this<!>("A")
}<!>
<!NO_ACTUAL_FOR_EXPECT!>expect class B : A {
constructor(i: Int)
constructor() : super("B")
constructor() : <!EXPECTED_CLASS_CONSTRUCTOR_DELEGATION_CALL!>super<!>("B")
}<!>
@@ -13,7 +13,7 @@
"no"
}
constructor() : this("no")
constructor() : <!EXPECTED_CLASS_CONSTRUCTOR_DELEGATION_CALL!>this<!>("no")
val prop: String = <!EXPECTED_PROPERTY_INITIALIZER!>"no"<!>