[FIR] Fix false positive errors for members with explicit API mode, ^KT-51758 Fixed
This commit is contained in:
+6
@@ -30994,6 +30994,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/mustBeEffectivelyPublic.kt");
|
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/mustBeEffectivelyPublic.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("noErrorsForMemebersInsideInternalDeclaration.kt")
|
||||||
|
public void testNoErrorsForMemebersInsideInternalDeclaration() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/noErrorsForMemebersInsideInternalDeclaration.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("properties.kt")
|
@TestMetadata("properties.kt")
|
||||||
public void testProperties() throws Exception {
|
public void testProperties() throws Exception {
|
||||||
|
|||||||
+6
@@ -30994,6 +30994,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
|||||||
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/mustBeEffectivelyPublic.kt");
|
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/mustBeEffectivelyPublic.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("noErrorsForMemebersInsideInternalDeclaration.kt")
|
||||||
|
public void testNoErrorsForMemebersInsideInternalDeclaration() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/noErrorsForMemebersInsideInternalDeclaration.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("properties.kt")
|
@TestMetadata("properties.kt")
|
||||||
public void testProperties() throws Exception {
|
public void testProperties() throws Exception {
|
||||||
|
|||||||
+6
@@ -30994,6 +30994,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
|||||||
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/mustBeEffectivelyPublic.kt");
|
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/mustBeEffectivelyPublic.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("noErrorsForMemebersInsideInternalDeclaration.kt")
|
||||||
|
public void testNoErrorsForMemebersInsideInternalDeclaration() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/noErrorsForMemebersInsideInternalDeclaration.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("properties.kt")
|
@TestMetadata("properties.kt")
|
||||||
public void testProperties() throws Exception {
|
public void testProperties() throws Exception {
|
||||||
|
|||||||
+9
-8
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirPrimaryConstructor
|
|||||||
import org.jetbrains.kotlin.fir.declarations.utils.effectiveVisibility
|
import org.jetbrains.kotlin.fir.declarations.utils.effectiveVisibility
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.isData
|
import org.jetbrains.kotlin.fir.declarations.utils.isData
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.isOverride
|
import org.jetbrains.kotlin.fir.declarations.utils.isOverride
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.utils.visibility
|
||||||
import org.jetbrains.kotlin.fir.resolve.transformers.publishedApiEffectiveVisibility
|
import org.jetbrains.kotlin.fir.resolve.transformers.publishedApiEffectiveVisibility
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
@@ -47,6 +48,10 @@ object FirExplicitApiDeclarationChecker : FirDeclarationSyntaxChecker<FirDeclara
|
|||||||
// Enum entries do not have visibilities
|
// Enum entries do not have visibilities
|
||||||
if (element is FirEnumEntry) return
|
if (element is FirEnumEntry) return
|
||||||
if (!element.effectiveVisibility.publicApi && element.publishedApiEffectiveVisibility == null) return
|
if (!element.effectiveVisibility.publicApi && element.publishedApiEffectiveVisibility == null) return
|
||||||
|
val lastDeclaration = context.containingDeclarations.lastOrNull()
|
||||||
|
if ((lastDeclaration as? FirMemberDeclaration)?.effectiveVisibility?.publicApi == false) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
checkVisibilityModifier(state, element, source, context, reporter)
|
checkVisibilityModifier(state, element, source, context, reporter)
|
||||||
checkExplicitReturnType(state, element, source, context, reporter)
|
checkExplicitReturnType(state, element, source, context, reporter)
|
||||||
@@ -85,14 +90,10 @@ object FirExplicitApiDeclarationChecker : FirDeclarationSyntaxChecker<FirDeclara
|
|||||||
*/
|
*/
|
||||||
private fun explicitVisibilityIsNotRequired(declaration: FirMemberDeclaration, context: CheckerContext): Boolean {
|
private fun explicitVisibilityIsNotRequired(declaration: FirMemberDeclaration, context: CheckerContext): Boolean {
|
||||||
return when (declaration) {
|
return when (declaration) {
|
||||||
// 1,
|
is FirPrimaryConstructor, // 1,
|
||||||
is FirPrimaryConstructor,
|
is FirPropertyAccessor, // 4
|
||||||
// 4
|
is FirValueParameter, // 6
|
||||||
is FirPropertyAccessor,
|
is FirAnonymousFunction -> true // 7
|
||||||
// 6
|
|
||||||
is FirValueParameter,
|
|
||||||
// 7
|
|
||||||
is FirAnonymousFunction -> true
|
|
||||||
is FirCallableDeclaration -> {
|
is FirCallableDeclaration -> {
|
||||||
val containingClass = context.containingDeclarations.lastOrNull() as? FirRegularClass
|
val containingClass = context.containingDeclarations.lastOrNull() as? FirRegularClass
|
||||||
// 2, 5
|
// 2, 5
|
||||||
|
|||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// SKIP_TXT
|
||||||
|
// ISSUE: KT-51758
|
||||||
|
|
||||||
|
@PublishedApi
|
||||||
|
internal class SomeClass {
|
||||||
|
private val somethingPrivate = "123"
|
||||||
|
|
||||||
|
public val somethingPublic = "456"
|
||||||
|
|
||||||
|
fun foo() = "789"
|
||||||
|
}
|
||||||
|
|
||||||
|
@PublishedApi
|
||||||
|
internal class Outer {
|
||||||
|
class Inner {
|
||||||
|
private val somethingPrivate = "123"
|
||||||
|
|
||||||
|
public val somethingPublic = "456"
|
||||||
|
|
||||||
|
fun foo() = "789"
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+6
@@ -31084,6 +31084,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/mustBeEffectivelyPublic.kt");
|
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/mustBeEffectivelyPublic.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("noErrorsForMemebersInsideInternalDeclaration.kt")
|
||||||
|
public void testNoErrorsForMemebersInsideInternalDeclaration() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/noErrorsForMemebersInsideInternalDeclaration.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("properties.kt")
|
@TestMetadata("properties.kt")
|
||||||
public void testProperties() throws Exception {
|
public void testProperties() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user