[FIR] Let FirTopLevelFunctionsChecker run on all platforms
Use a session component to control platform specific suppression logic.
This commit is contained in:
committed by
Space Team
parent
085df96afe
commit
d6e14f37a7
+1
-1
@@ -16,7 +16,7 @@ private fun FirDeclaration.isLexicallyInsideJsNative(context: CheckerContext): B
|
||||
return JsStandardClassIds.Annotations.nativeAnnotations.any { hasAnnotationOrInsideAnnotatedClass(it, context.session) }
|
||||
}
|
||||
|
||||
object FirJsPlatformDiagnosticSuppressor : FirPlatformDiagnosticSuppressor {
|
||||
class FirJsPlatformDiagnosticSuppressor : FirPlatformDiagnosticSuppressor {
|
||||
override fun shouldReportNoBody(declaration: FirCallableDeclaration, context: CheckerContext) =
|
||||
!declaration.isLexicallyInsideJsNative(context)
|
||||
}
|
||||
|
||||
-1
@@ -40,7 +40,6 @@ object JsDeclarationCheckers : DeclarationCheckers() {
|
||||
|
||||
override val simpleFunctionCheckers: Set<FirSimpleFunctionChecker>
|
||||
get() = setOf(
|
||||
FirJsTopLevelFunctionsChecker,
|
||||
FirJsNativeInvokeChecker,
|
||||
FirJsNativeGetterChecker,
|
||||
FirJsNativeSetterChecker,
|
||||
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.js.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirTopLevelFunctionsChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.js.checkers.FirJsPlatformDiagnosticSuppressor
|
||||
|
||||
object FirJsTopLevelFunctionsChecker : FirTopLevelFunctionsChecker() {
|
||||
override val suppressor = FirJsPlatformDiagnosticSuppressor
|
||||
}
|
||||
-5
@@ -51,9 +51,4 @@ object JvmDeclarationCheckers : DeclarationCheckers() {
|
||||
get() = setOf(
|
||||
FirUpperBoundsChecker,
|
||||
)
|
||||
|
||||
override val simpleFunctionCheckers: Set<FirSimpleFunctionChecker>
|
||||
get() = setOf(
|
||||
FirJvmTopLevelFunctionsChecker,
|
||||
)
|
||||
}
|
||||
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.jvm.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.FirPlatformDiagnosticSuppressor
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirTopLevelFunctionsChecker
|
||||
|
||||
object FirJvmTopLevelFunctionsChecker : FirTopLevelFunctionsChecker() {
|
||||
override val suppressor = FirPlatformDiagnosticSuppressor.Default
|
||||
}
|
||||
+1
@@ -58,6 +58,7 @@ object CommonDeclarationCheckers : DeclarationCheckers() {
|
||||
FirMemberFunctionsChecker,
|
||||
FirDataObjectContentChecker,
|
||||
ContractSyntaxV2FunctionChecker,
|
||||
FirTopLevelFunctionsChecker,
|
||||
)
|
||||
|
||||
override val propertyCheckers: Set<FirPropertyChecker>
|
||||
|
||||
+2
-5
@@ -5,13 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSessionComponent
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
||||
|
||||
interface FirPlatformDiagnosticSuppressor {
|
||||
interface FirPlatformDiagnosticSuppressor : FirSessionComponent {
|
||||
fun shouldReportNoBody(declaration: FirCallableDeclaration, context: CheckerContext): Boolean
|
||||
|
||||
object Default : FirPlatformDiagnosticSuppressor {
|
||||
override fun shouldReportNoBody(declaration: FirCallableDeclaration, context: CheckerContext): Boolean = true
|
||||
}
|
||||
}
|
||||
|
||||
+8
-4
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.FirPlatformDiagnosticSuppressor
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.hasModifier
|
||||
@@ -18,10 +19,10 @@ import org.jetbrains.kotlin.fir.declarations.utils.isExpect
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isExternal
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
// See old FE's [DeclarationsChecker]
|
||||
abstract class FirTopLevelFunctionsChecker : FirSimpleFunctionChecker() {
|
||||
abstract val suppressor: FirPlatformDiagnosticSuppressor
|
||||
val FirSession.platformDiagnosticSuppressor: FirPlatformDiagnosticSuppressor? by FirSession.nullableSessionComponentAccessor()
|
||||
|
||||
// See old FE's [DeclarationsChecker]
|
||||
object FirTopLevelFunctionsChecker : FirSimpleFunctionChecker() {
|
||||
override fun check(declaration: FirSimpleFunction, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
// Only report on top level callable declarations
|
||||
if (context.containingDeclarations.size > 1) return
|
||||
@@ -32,7 +33,10 @@ abstract class FirTopLevelFunctionsChecker : FirSimpleFunctionChecker() {
|
||||
// So, our source of truth should be the full modifier list retrieved from the source.
|
||||
if (declaration.hasModifier(KtTokens.ABSTRACT_KEYWORD)) return
|
||||
if (declaration.isExternal) return
|
||||
if (!declaration.hasBody && !declaration.isExpect && suppressor.shouldReportNoBody(declaration, context)) {
|
||||
if (!declaration.hasBody &&
|
||||
!declaration.isExpect &&
|
||||
context.session.platformDiagnosticSuppressor?.shouldReportNoBody(declaration, context) != false
|
||||
) {
|
||||
reporter.reportOn(source, FirErrors.NON_MEMBER_FUNCTION_NO_BODY, declaration.symbol, context)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.FirVisibilityChecker
|
||||
import org.jetbrains.kotlin.fir.SessionConfiguration
|
||||
import org.jetbrains.kotlin.fir.analysis.FirOverridesBackwardCompatibilityHelper
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.FirPlatformDiagnosticSuppressor
|
||||
import org.jetbrains.kotlin.fir.analysis.js.checkers.FirJsPlatformDiagnosticSuppressor
|
||||
import org.jetbrains.kotlin.fir.checkers.registerJsCheckers
|
||||
import org.jetbrains.kotlin.fir.deserialization.ModuleDataProvider
|
||||
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar
|
||||
@@ -44,7 +46,7 @@ object FirJsSessionFactory : FirAbstractSessionFactory() {
|
||||
null,
|
||||
init,
|
||||
registerExtraComponents = { session ->
|
||||
session.registerJsSpecificResolveComponents()
|
||||
session.registerJsSpecificComponents()
|
||||
registerExtraComponents(session)
|
||||
},
|
||||
registerExtraCheckers = { it.registerJsCheckers() },
|
||||
@@ -75,7 +77,7 @@ object FirJsSessionFactory : FirAbstractSessionFactory() {
|
||||
languageVersionSettings,
|
||||
extensionRegistrars,
|
||||
registerExtraComponents = {
|
||||
it.registerJsSpecificResolveComponents()
|
||||
it.registerJsSpecificComponents()
|
||||
registerExtraComponents(it)
|
||||
},
|
||||
createKotlinScopeProvider = { FirKotlinScopeProvider { _, declaredMemberScope, _, _, _ -> declaredMemberScope } },
|
||||
@@ -92,10 +94,11 @@ object FirJsSessionFactory : FirAbstractSessionFactory() {
|
||||
)
|
||||
|
||||
@OptIn(SessionConfiguration::class)
|
||||
fun FirSession.registerJsSpecificResolveComponents() {
|
||||
fun FirSession.registerJsSpecificComponents() {
|
||||
register(FirVisibilityChecker::class, FirVisibilityChecker.Default)
|
||||
register(ConeCallConflictResolverFactory::class, JsCallConflictResolverFactory)
|
||||
register(FirPlatformClassMapper::class, FirPlatformClassMapper.Default)
|
||||
register(FirOverridesBackwardCompatibilityHelper::class, FirOverridesBackwardCompatibilityHelper.Default())
|
||||
register(FirPlatformDiagnosticSuppressor::class, FirJsPlatformDiagnosticSuppressor())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user