FIR: fix API mode checker for local functions

This commit is contained in:
Tianyu Geng
2021-10-21 14:53:54 -07:00
committed by Mikhail Glukhikh
parent 31b7248769
commit a969e5af50
9 changed files with 55 additions and 5 deletions
@@ -30261,6 +30261,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/interfaces.kt");
}
@Test
@TestMetadata("localFunctions.kt")
public void testLocalFunctions() throws Exception {
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/localFunctions.kt");
}
@Test
@TestMetadata("mustBeEffectivelyPublic.kt")
public void testMustBeEffectivelyPublic() throws Exception {
@@ -30261,6 +30261,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/interfaces.kt");
}
@Test
@TestMetadata("localFunctions.kt")
public void testLocalFunctions() throws Exception {
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/localFunctions.kt");
}
@Test
@TestMetadata("mustBeEffectivelyPublic.kt")
public void testMustBeEffectivelyPublic() throws Exception {
@@ -30261,6 +30261,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/interfaces.kt");
}
@Test
@TestMetadata("localFunctions.kt")
public void testLocalFunctions() throws Exception {
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/localFunctions.kt");
}
@Test
@TestMetadata("mustBeEffectivelyPublic.kt")
public void testMustBeEffectivelyPublic() throws Exception {
@@ -386,7 +386,7 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
parameter<String>("message")
}
val NO_EXPLICIT_VISIBILITY_IN_API_MODE by warning<KtDeclaration>(PositioningStrategy.DECLARATION_START_TO_NAME)
val NO_EXPLICIT_VISIBILITY_IN_API_MODE by error<KtDeclaration>(PositioningStrategy.DECLARATION_START_TO_NAME)
val NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING by warning<KtDeclaration>(PositioningStrategy.DECLARATION_START_TO_NAME)
val NO_EXPLICIT_RETURN_TYPE_IN_API_MODE by error<KtDeclaration>(PositioningStrategy.DECLARATION_NAME)
@@ -288,7 +288,7 @@ object FirErrors {
val WRONG_MODIFIER_CONTAINING_DECLARATION by error2<PsiElement, KtModifierKeywordToken, String>()
val DEPRECATED_MODIFIER_CONTAINING_DECLARATION by warning2<PsiElement, KtModifierKeywordToken, String>()
val INAPPLICABLE_OPERATOR_MODIFIER by error1<PsiElement, String>(SourceElementPositioningStrategies.OPERATOR_MODIFIER)
val NO_EXPLICIT_VISIBILITY_IN_API_MODE by warning0<KtDeclaration>(SourceElementPositioningStrategies.DECLARATION_START_TO_NAME)
val NO_EXPLICIT_VISIBILITY_IN_API_MODE by error0<KtDeclaration>(SourceElementPositioningStrategies.DECLARATION_START_TO_NAME)
val NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING by warning0<KtDeclaration>(SourceElementPositioningStrategies.DECLARATION_START_TO_NAME)
val NO_EXPLICIT_RETURN_TYPE_IN_API_MODE by error0<KtDeclaration>(SourceElementPositioningStrategies.DECLARATION_NAME)
val NO_EXPLICIT_RETURN_TYPE_IN_API_MODE_WARNING by warning0<KtDeclaration>(SourceElementPositioningStrategies.DECLARATION_NAME)
@@ -76,6 +76,8 @@ object FirExplicitApiDeclarationChecker : FirDeclarationSyntaxChecker<FirDeclara
* 4. Getters and setters (because getters can't change visibility and setter-only explicit visibility looks ugly)
* 5. Properties of annotations in public API
* 6. Value parameter declaration
* 7. An anonymous function
* 8. A local named function
*
* TODO: Do we need something like @PublicApiFile to disable (or invert) this inspection per-file?
*/
@@ -86,7 +88,9 @@ object FirExplicitApiDeclarationChecker : FirDeclarationSyntaxChecker<FirDeclara
// 4
is FirPropertyAccessor,
// 6
is FirValueParameter -> true
is FirValueParameter,
// 7
is FirAnonymousFunction -> true
is FirCallableDeclaration -> {
val containingClass = context.containingDeclarations.lastOrNull() as? FirRegularClass
// 2, 5
@@ -97,8 +101,8 @@ object FirExplicitApiDeclarationChecker : FirDeclarationSyntaxChecker<FirDeclara
return true
}
// 3
declaration.isOverride
// 3, 8
declaration.isOverride || declaration.isLocalMember
}
else -> false
}
@@ -0,0 +1,18 @@
// FIR_IDENTICAL
<!NO_EXPLICIT_VISIBILITY_IN_API_MODE!>fun run<!>(b: () -> Unit) {}
<!NO_EXPLICIT_VISIBILITY_IN_API_MODE!>fun test<!>() {
run {
}
fun localFun() {}
localFun()
run(::localFun)
val localFun2 = fun() {}
run(localFun2)
val lambda = {}
run(lambda)
}
@@ -0,0 +1,4 @@
package
public fun run(/*0*/ b: () -> kotlin.Unit): kotlin.Unit
public fun test(): kotlin.Unit
@@ -30357,6 +30357,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/interfaces.kt");
}
@Test
@TestMetadata("localFunctions.kt")
public void testLocalFunctions() throws Exception {
runTest("compiler/testData/diagnostics/tests/testsWithExplicitApi/localFunctions.kt");
}
@Test
@TestMetadata("mustBeEffectivelyPublic.kt")
public void testMustBeEffectivelyPublic() throws Exception {