From f7c68afb18df8e8331507513d2fccdbea22f0d8b Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 30 Jun 2021 15:09:42 +0300 Subject: [PATCH] [FIR] Don't report EXPOSED_FUNCTION_RETURN_TYPE on property accessors --- ...irOldFrontendDiagnosticsTestGenerated.java | 6 ++++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 ++++ .../FirExposedVisibilityDeclarationChecker.kt | 2 +- .../tests/visibility/protectedInternal.kt | 13 ++++++++ .../tests/visibility/protectedInternal.txt | 31 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++ ...CompilerTestFE10TestdataTestGenerated.java | 6 ++++ 7 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/visibility/protectedInternal.kt create mode 100644 compiler/testData/diagnostics/tests/visibility/protectedInternal.txt 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 30fd40b3ad8..cbec58cd9ee 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 @@ -30930,6 +30930,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti public void testLackOfInvisibleSetterOfJavaClassInSamePackage() throws Exception { runTest("compiler/testData/diagnostics/tests/visibility/lackOfInvisibleSetterOfJavaClassInSamePackage.kt"); } + + @Test + @TestMetadata("protectedInternal.kt") + public void testProtectedInternal() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/protectedInternal.kt"); + } } @Nested 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 4b21cb29918..be2c1fb1897 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 @@ -30930,6 +30930,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac public void testLackOfInvisibleSetterOfJavaClassInSamePackage() throws Exception { runTest("compiler/testData/diagnostics/tests/visibility/lackOfInvisibleSetterOfJavaClassInSamePackage.kt"); } + + @Test + @TestMetadata("protectedInternal.kt") + public void testProtectedInternal() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/protectedInternal.kt"); + } } @Nested diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExposedVisibilityDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExposedVisibilityDeclarationChecker.kt index b3f5dcdca07..2f8ae0c78e8 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExposedVisibilityDeclarationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExposedVisibilityDeclarationChecker.kt @@ -110,7 +110,7 @@ object FirExposedVisibilityDeclarationChecker : FirBasicDeclarationChecker() { val functionVisibility = (declaration as FirMemberDeclaration).effectiveVisibility if (functionVisibility == EffectiveVisibility.Local) return - if (declaration !is FirConstructor) { + if (declaration !is FirConstructor && declaration !is FirPropertyAccessor) { val restricting = declaration.returnTypeRef.coneTypeSafe() ?.findVisibilityExposure(context, functionVisibility) if (restricting != null) { diff --git a/compiler/testData/diagnostics/tests/visibility/protectedInternal.kt b/compiler/testData/diagnostics/tests/visibility/protectedInternal.kt new file mode 100644 index 00000000000..90ba59bc74c --- /dev/null +++ b/compiler/testData/diagnostics/tests/visibility/protectedInternal.kt @@ -0,0 +1,13 @@ +// FIR_IDENTICAL +abstract class A + +internal class B : A() + +abstract class Base { + protected abstract val a: A +} + +internal class Derived : Base() { + override val a = B() + get() = field +} diff --git a/compiler/testData/diagnostics/tests/visibility/protectedInternal.txt b/compiler/testData/diagnostics/tests/visibility/protectedInternal.txt new file mode 100644 index 00000000000..4e2a31be9f0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/visibility/protectedInternal.txt @@ -0,0 +1,31 @@ +package + +public abstract class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class B : A { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Base { + public constructor Base() + protected abstract val a: A + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class Derived : Base { + public constructor Derived() + protected open override /*1*/ val a: B + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} 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 f268b57c503..29ce586434b 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 @@ -31026,6 +31026,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { public void testLackOfInvisibleSetterOfJavaClassInSamePackage() throws Exception { runTest("compiler/testData/diagnostics/tests/visibility/lackOfInvisibleSetterOfJavaClassInSamePackage.kt"); } + + @Test + @TestMetadata("protectedInternal.kt") + public void testProtectedInternal() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/protectedInternal.kt"); + } } @Nested diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 2c904856bec..6db985c6183 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -30930,6 +30930,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag public void testLackOfInvisibleSetterOfJavaClassInSamePackage() throws Exception { runTest("compiler/testData/diagnostics/tests/visibility/lackOfInvisibleSetterOfJavaClassInSamePackage.kt"); } + + @Test + @TestMetadata("protectedInternal.kt") + public void testProtectedInternal() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/protectedInternal.kt"); + } } @Nested