[K2] Rewrite condition for EXPECTED_PRIVATE_DECLARATION
...without `isTopLevelOrInsideClass` property. Behavior stays the same, because in fact we require all `expect` member declarations to be non-private except constructors and property setter. Enhance already existing test. ^KT-59899
This commit is contained in:
committed by
Space Team
parent
1fdc607898
commit
6112c4ab2c
+3
-6
@@ -23,10 +23,7 @@ object FirExpectConsistencyChecker : FirBasicDeclarationChecker() {
|
|||||||
val source = declaration.source ?: return
|
val source = declaration.source ?: return
|
||||||
if (source.kind is KtFakeSourceElementKind) return
|
if (source.kind is KtFakeSourceElementKind) return
|
||||||
|
|
||||||
val isTopLevel = context.containingDeclarations.size == 1
|
|
||||||
val lastClass = context.containingDeclarations.lastOrNull() as? FirClass
|
val lastClass = context.containingDeclarations.lastOrNull() as? FirClass
|
||||||
val isTopLevelOrInsideClass = isTopLevel || lastClass != null
|
|
||||||
|
|
||||||
if (declaration is FirAnonymousInitializer) {
|
if (declaration is FirAnonymousInitializer) {
|
||||||
if (lastClass?.isExpect == true) {
|
if (lastClass?.isExpect == true) {
|
||||||
reporter.reportOn(source, FirErrors.EXPECTED_DECLARATION_WITH_BODY, context)
|
reporter.reportOn(source, FirErrors.EXPECTED_DECLARATION_WITH_BODY, context)
|
||||||
@@ -42,7 +39,7 @@ object FirExpectConsistencyChecker : FirBasicDeclarationChecker() {
|
|||||||
reporter.reportOn(delegatedConstructor.source, FirErrors.EXPECTED_CLASS_CONSTRUCTOR_DELEGATION_CALL, context)
|
reporter.reportOn(delegatedConstructor.source, FirErrors.EXPECTED_CLASS_CONSTRUCTOR_DELEGATION_CALL, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isProhibitedPrivateDeclaration(declaration, isTopLevelOrInsideClass)) {
|
if (isProhibitedPrivateDeclaration(declaration)) {
|
||||||
reporter.reportOn(source, FirErrors.EXPECTED_PRIVATE_DECLARATION, context)
|
reporter.reportOn(source, FirErrors.EXPECTED_PRIVATE_DECLARATION, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,8 +61,8 @@ object FirExpectConsistencyChecker : FirBasicDeclarationChecker() {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isProhibitedPrivateDeclaration(declaration: FirMemberDeclaration, isTopLevelOrInsideClass: Boolean): Boolean {
|
private fun isProhibitedPrivateDeclaration(declaration: FirMemberDeclaration): Boolean {
|
||||||
return isTopLevelOrInsideClass && declaration !is FirConstructor && Visibilities.isPrivate(declaration.visibility)
|
return declaration !is FirConstructor && declaration !is FirPropertyAccessor && Visibilities.isPrivate(declaration.visibility)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isProhibitedDeclarationWithBody(declaration: FirMemberDeclaration): Boolean {
|
private fun isProhibitedDeclarationWithBody(declaration: FirMemberDeclaration): Boolean {
|
||||||
|
|||||||
+8
-2
@@ -1,21 +1,27 @@
|
|||||||
// MODULE: m1-common
|
// MODULE: m1-common
|
||||||
// FILE: common.kt
|
// FILE: common.kt
|
||||||
|
|
||||||
expect class A {
|
expect class A private constructor() {
|
||||||
<!EXPECTED_PRIVATE_DECLARATION!>private<!> fun foo()
|
<!EXPECTED_PRIVATE_DECLARATION!>private<!> fun foo()
|
||||||
<!EXPECTED_PRIVATE_DECLARATION!>private<!> val bar: String
|
<!EXPECTED_PRIVATE_DECLARATION!>private<!> val bar: String
|
||||||
<!EXPECTED_PRIVATE_DECLARATION!>private<!> fun Int.memExt(): Any
|
<!EXPECTED_PRIVATE_DECLARATION!>private<!> fun Int.memExt(): Any
|
||||||
|
|
||||||
<!EXPECTED_PRIVATE_DECLARATION!>private<!> class Nested
|
<!EXPECTED_PRIVATE_DECLARATION!>private<!> class Nested
|
||||||
|
|
||||||
|
var baz: Any?
|
||||||
|
private set
|
||||||
}
|
}
|
||||||
|
|
||||||
// MODULE: m1-jvm()()(m1-common)
|
// MODULE: m1-jvm()()(m1-common)
|
||||||
// FILE: jvm.kt
|
// FILE: jvm.kt
|
||||||
|
|
||||||
actual class A {
|
actual class A actual private constructor() {
|
||||||
private fun foo() {}
|
private fun foo() {}
|
||||||
private val bar: String = ""
|
private val bar: String = ""
|
||||||
actual private fun Int.memExt(): Any = 0
|
actual private fun Int.memExt(): Any = 0
|
||||||
|
|
||||||
actual private class Nested
|
actual private class Nested
|
||||||
|
|
||||||
|
actual var baz: Any? = null
|
||||||
|
private set
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-2
@@ -1,21 +1,27 @@
|
|||||||
// MODULE: m1-common
|
// MODULE: m1-common
|
||||||
// FILE: common.kt
|
// FILE: common.kt
|
||||||
|
|
||||||
expect class A {
|
expect class A private constructor() {
|
||||||
<!EXPECTED_PRIVATE_DECLARATION, EXPECTED_PRIVATE_DECLARATION{JVM}!>private<!> fun foo()
|
<!EXPECTED_PRIVATE_DECLARATION, EXPECTED_PRIVATE_DECLARATION{JVM}!>private<!> fun foo()
|
||||||
<!EXPECTED_PRIVATE_DECLARATION, EXPECTED_PRIVATE_DECLARATION{JVM}!>private<!> val bar: String
|
<!EXPECTED_PRIVATE_DECLARATION, EXPECTED_PRIVATE_DECLARATION{JVM}!>private<!> val bar: String
|
||||||
<!EXPECTED_PRIVATE_DECLARATION, EXPECTED_PRIVATE_DECLARATION{JVM}!>private<!> fun Int.memExt(): Any
|
<!EXPECTED_PRIVATE_DECLARATION, EXPECTED_PRIVATE_DECLARATION{JVM}!>private<!> fun Int.memExt(): Any
|
||||||
|
|
||||||
<!EXPECTED_PRIVATE_DECLARATION, EXPECTED_PRIVATE_DECLARATION{JVM}!>private<!> class Nested
|
<!EXPECTED_PRIVATE_DECLARATION, EXPECTED_PRIVATE_DECLARATION{JVM}!>private<!> class Nested
|
||||||
|
|
||||||
|
var baz: Any?
|
||||||
|
private set
|
||||||
}
|
}
|
||||||
|
|
||||||
// MODULE: m1-jvm()()(m1-common)
|
// MODULE: m1-jvm()()(m1-common)
|
||||||
// FILE: jvm.kt
|
// FILE: jvm.kt
|
||||||
|
|
||||||
actual class A {
|
actual class A actual private constructor() {
|
||||||
private fun <!ACTUAL_MISSING!>foo<!>() {}
|
private fun <!ACTUAL_MISSING!>foo<!>() {}
|
||||||
private val <!ACTUAL_MISSING!>bar<!>: String = ""
|
private val <!ACTUAL_MISSING!>bar<!>: String = ""
|
||||||
actual private fun Int.memExt(): Any = 0
|
actual private fun Int.memExt(): Any = 0
|
||||||
|
|
||||||
actual private class Nested
|
actual private class Nested
|
||||||
|
|
||||||
|
actual var baz: Any? = null
|
||||||
|
private set
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -2,7 +2,9 @@
|
|||||||
package
|
package
|
||||||
|
|
||||||
public final expect class A {
|
public final expect class A {
|
||||||
|
private constructor A()
|
||||||
private expect final val bar: kotlin.String
|
private expect final val bar: kotlin.String
|
||||||
|
public expect final var baz: kotlin.Any?
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
private final expect fun foo(): kotlin.Unit
|
private final expect fun foo(): kotlin.Unit
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
@@ -20,8 +22,9 @@ public final expect class A {
|
|||||||
package
|
package
|
||||||
|
|
||||||
public final actual class A {
|
public final actual class A {
|
||||||
public constructor A()
|
private constructor A()
|
||||||
private final val bar: kotlin.String = ""
|
private final val bar: kotlin.String = ""
|
||||||
|
public actual final var baz: kotlin.Any?
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
private final fun foo(): kotlin.Unit
|
private final fun foo(): kotlin.Unit
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
|||||||
Reference in New Issue
Block a user