From a969e5af50481f1a7261f683f0c6433bdebae3b6 Mon Sep 17 00:00:00 2001 From: Tianyu Geng Date: Thu, 21 Oct 2021 14:53:54 -0700 Subject: [PATCH] FIR: fix API mode checker for local functions --- ...sCompilerTestFE10TestdataTestGenerated.java | 6 ++++++ ...FirOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ ...dDiagnosticsWithLightTreeTestGenerated.java | 6 ++++++ .../diagnostics/FirDiagnosticsList.kt | 2 +- .../fir/analysis/diagnostics/FirErrors.kt | 2 +- .../syntax/FirExplicitApiDeclarationChecker.kt | 10 +++++++--- .../testsWithExplicitApi/localFunctions.kt | 18 ++++++++++++++++++ .../testsWithExplicitApi/localFunctions.txt | 4 ++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++++ 9 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/testsWithExplicitApi/localFunctions.kt create mode 100644 compiler/testData/diagnostics/tests/testsWithExplicitApi/localFunctions.txt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index a17c41fc7b2..bc5d894f322 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -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 { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 4c30206fec2..db3a7df97e5 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -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 { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index c7aac8c8c48..d2fdcd5319d 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -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 { diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt index 1035ef1096a..274b33135df 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt @@ -386,7 +386,7 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") { parameter("message") } - val NO_EXPLICIT_VISIBILITY_IN_API_MODE by warning(PositioningStrategy.DECLARATION_START_TO_NAME) + val NO_EXPLICIT_VISIBILITY_IN_API_MODE by error(PositioningStrategy.DECLARATION_START_TO_NAME) val NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING by warning(PositioningStrategy.DECLARATION_START_TO_NAME) val NO_EXPLICIT_RETURN_TYPE_IN_API_MODE by error(PositioningStrategy.DECLARATION_NAME) diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index 4a60f5871cd..d4effb06644 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -288,7 +288,7 @@ object FirErrors { val WRONG_MODIFIER_CONTAINING_DECLARATION by error2() val DEPRECATED_MODIFIER_CONTAINING_DECLARATION by warning2() val INAPPLICABLE_OPERATOR_MODIFIER by error1(SourceElementPositioningStrategies.OPERATOR_MODIFIER) - val NO_EXPLICIT_VISIBILITY_IN_API_MODE by warning0(SourceElementPositioningStrategies.DECLARATION_START_TO_NAME) + val NO_EXPLICIT_VISIBILITY_IN_API_MODE by error0(SourceElementPositioningStrategies.DECLARATION_START_TO_NAME) val NO_EXPLICIT_VISIBILITY_IN_API_MODE_WARNING by warning0(SourceElementPositioningStrategies.DECLARATION_START_TO_NAME) val NO_EXPLICIT_RETURN_TYPE_IN_API_MODE by error0(SourceElementPositioningStrategies.DECLARATION_NAME) val NO_EXPLICIT_RETURN_TYPE_IN_API_MODE_WARNING by warning0(SourceElementPositioningStrategies.DECLARATION_NAME) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/syntax/FirExplicitApiDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/syntax/FirExplicitApiDeclarationChecker.kt index 3705684366f..0fa1c4e8f75 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/syntax/FirExplicitApiDeclarationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/syntax/FirExplicitApiDeclarationChecker.kt @@ -76,6 +76,8 @@ object FirExplicitApiDeclarationChecker : FirDeclarationSyntaxChecker 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 false } diff --git a/compiler/testData/diagnostics/tests/testsWithExplicitApi/localFunctions.kt b/compiler/testData/diagnostics/tests/testsWithExplicitApi/localFunctions.kt new file mode 100644 index 00000000000..08c1d67e5c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/testsWithExplicitApi/localFunctions.kt @@ -0,0 +1,18 @@ +// FIR_IDENTICAL +fun run(b: () -> Unit) {} + +fun test() { + run { + + } + + fun localFun() {} + localFun() + run(::localFun) + + val localFun2 = fun() {} + run(localFun2) + + val lambda = {} + run(lambda) +} diff --git a/compiler/testData/diagnostics/tests/testsWithExplicitApi/localFunctions.txt b/compiler/testData/diagnostics/tests/testsWithExplicitApi/localFunctions.txt new file mode 100644 index 00000000000..81d0e1eaf36 --- /dev/null +++ b/compiler/testData/diagnostics/tests/testsWithExplicitApi/localFunctions.txt @@ -0,0 +1,4 @@ +package + +public fun run(/*0*/ b: () -> kotlin.Unit): kotlin.Unit +public fun test(): kotlin.Unit diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index dbe2b35d91f..10604741bba 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -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 {