[FIR] KT-56505 Fix checkVisibilityModifier taking wrong modifier list
- KT-56505 occurred because `source.getChild(KtNodeTypes.MODIFIER_LIST)` returns any modifier list in the subtree of the source element, not necessarily the modifier list belonging to the checked element. `depth = 1` restricts the search to the modifier list belonging to the checked element itself. - For example, given `f1` from KT-56505, `getChild` would return the modifier list of `public var foo = 0`. Because it contains a visibility modifier, `f1` wasn't marked with `NO_EXPLICIT_VISIBILITY_IN_API_MODE`. ^KT-56505 fixed
This commit is contained in:
committed by
Space Team
parent
e86c877733
commit
5d391bc261
+3
-4
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirPrimaryConstructor
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.effectiveVisibility
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isData
|
||||
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.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
@@ -48,8 +47,8 @@ object FirExplicitApiDeclarationChecker : FirDeclarationSyntaxChecker<FirDeclara
|
||||
// Enum entries do not have visibilities
|
||||
if (element is FirEnumEntry) return
|
||||
if (!element.effectiveVisibility.publicApi && element.publishedApiEffectiveVisibility == null) return
|
||||
val lastDeclaration = context.containingDeclarations.lastOrNull()
|
||||
if ((lastDeclaration as? FirMemberDeclaration)?.effectiveVisibility?.publicApi == false) {
|
||||
val lastContainingDeclaration = context.containingDeclarations.lastOrNull()
|
||||
if ((lastContainingDeclaration as? FirMemberDeclaration)?.effectiveVisibility?.publicApi == false) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -64,7 +63,7 @@ object FirExplicitApiDeclarationChecker : FirDeclarationSyntaxChecker<FirDeclara
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
) {
|
||||
val visibilityModifier = source.getChild(KtNodeTypes.MODIFIER_LIST)?.getChild(KtTokens.VISIBILITY_MODIFIERS)
|
||||
val visibilityModifier = source.getChild(KtNodeTypes.MODIFIER_LIST, depth = 1)?.getChild(KtTokens.VISIBILITY_MODIFIERS)
|
||||
if (visibilityModifier != null) return
|
||||
|
||||
if (explicitVisibilityIsNotRequired(declaration, context)) return
|
||||
|
||||
Reference in New Issue
Block a user