From 6a3b7a9f910a34f5090892db9bd066584c7e81e2 Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Thu, 10 Feb 2022 16:14:21 +0300 Subject: [PATCH] [FIR] Ignore fake functions in FirExposedVisibilityDeclarationChecker ^KT-51229 Fixed --- .../FirExposedVisibilityDeclarationChecker.kt | 6 +++- .../sealed/privateTypeInConstructor.fir.kt | 10 ++++++- .../tests/sealed/privateTypeInConstructor.kt | 10 ++++++- .../tests/sealed/privateTypeInConstructor.txt | 29 +++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) 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 4c96fc7bbee..f7f14ddce41 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 @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration +import org.jetbrains.kotlin.KtFakeSourceElementKind import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.EffectiveVisibility import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext @@ -101,8 +102,11 @@ object FirExposedVisibilityDeclarationChecker : FirBasicDeclarationChecker() { } private fun checkFunction(declaration: FirFunction, reporter: DiagnosticReporter, context: CheckerContext) { - var functionVisibility = (declaration as FirMemberDeclaration).effectiveVisibility + if (declaration.source?.kind is KtFakeSourceElementKind) { + return + } + var functionVisibility = (declaration as FirMemberDeclaration).effectiveVisibility if (declaration is FirConstructor && declaration.isFromSealedClass) { functionVisibility = EffectiveVisibility.PrivateInClass } diff --git a/compiler/testData/diagnostics/tests/sealed/privateTypeInConstructor.fir.kt b/compiler/testData/diagnostics/tests/sealed/privateTypeInConstructor.fir.kt index 008001164cc..40dc61ab284 100644 --- a/compiler/testData/diagnostics/tests/sealed/privateTypeInConstructor.fir.kt +++ b/compiler/testData/diagnostics/tests/sealed/privateTypeInConstructor.fir.kt @@ -1,4 +1,4 @@ -// ISSUE: KT-45043 +// ISSUE: KT-45043, KT-51229 // DIAGNOSTICS: -UNUSED_PARAMETER private class Bar @@ -14,3 +14,11 @@ abstract class AbstractFoo( private val y: Bar, z: Bar ) + +internal sealed class A { + protected abstract val b: B? + protected data class B(val s: String) + internal data class C private constructor(override val b: B?) : A() { + constructor() : this(null) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/sealed/privateTypeInConstructor.kt b/compiler/testData/diagnostics/tests/sealed/privateTypeInConstructor.kt index b102561ddd4..09cc0ad17c0 100644 --- a/compiler/testData/diagnostics/tests/sealed/privateTypeInConstructor.kt +++ b/compiler/testData/diagnostics/tests/sealed/privateTypeInConstructor.kt @@ -1,4 +1,4 @@ -// ISSUE: KT-45043 +// ISSUE: KT-45043, KT-51229 // DIAGNOSTICS: -UNUSED_PARAMETER private class Bar @@ -14,3 +14,11 @@ abstract class AbstractFoo( private val y: Bar, z: Bar ) + +internal sealed class A { + protected abstract val b: B? + protected data class B(val s: String) + internal data class C private constructor(override val b: B?) : A() { + constructor() : this(null) + } +} diff --git a/compiler/testData/diagnostics/tests/sealed/privateTypeInConstructor.txt b/compiler/testData/diagnostics/tests/sealed/privateTypeInConstructor.txt index 3f33b21eb9d..15338978390 100644 --- a/compiler/testData/diagnostics/tests/sealed/privateTypeInConstructor.txt +++ b/compiler/testData/diagnostics/tests/sealed/privateTypeInConstructor.txt @@ -1,5 +1,34 @@ package +internal sealed class A { + protected constructor A() + protected abstract val b: 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 + + protected final data class B { + public constructor B(/*0*/ s: kotlin.String) + public final val s: kotlin.String + public final operator /*synthesized*/ fun component1(): kotlin.String + public final /*synthesized*/ fun copy(/*0*/ s: kotlin.String = ...): A.B + public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String + } + + internal final data class C : A { + public constructor C() + private constructor C(/*0*/ b: A.B?) + protected open override /*1*/ val b: A.B? + protected final operator /*synthesized*/ fun component1(): A.B? + public final /*synthesized*/ fun copy(/*0*/ b: A.B? = ...): A.C + public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String + } +} + public abstract class AbstractFoo { public constructor AbstractFoo(/*0*/ x: Bar, /*1*/ y: Bar, /*2*/ z: Bar) public final val x: Bar