[FIR JS] Stop reporting NON_MEMBER_FUNCTION_NO_BODY for js natives
This commit is contained in:
committed by
Space Team
parent
85bcef537c
commit
2f9831ed99
+22
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.checkers.FirPlatformDiagnosticSuppressor
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.checkers.hasAnnotationOrInsideAnnotatedClass
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||||
|
import org.jetbrains.kotlin.name.JsStandardClassIds
|
||||||
|
|
||||||
|
private fun FirDeclaration.isLexicallyInsideJsNative(context: CheckerContext): Boolean {
|
||||||
|
return JsStandardClassIds.Annotations.nativeAnnotations.any { hasAnnotationOrInsideAnnotatedClass(it, context.session) }
|
||||||
|
}
|
||||||
|
|
||||||
|
object FirJsPlatformDiagnosticSuppressor : FirPlatformDiagnosticSuppressor {
|
||||||
|
override fun shouldReportNoBody(declaration: FirCallableDeclaration, context: CheckerContext) =
|
||||||
|
!declaration.isLexicallyInsideJsNative(context)
|
||||||
|
}
|
||||||
+1
@@ -37,6 +37,7 @@ object JsDeclarationCheckers : DeclarationCheckers() {
|
|||||||
|
|
||||||
override val simpleFunctionCheckers: Set<FirSimpleFunctionChecker>
|
override val simpleFunctionCheckers: Set<FirSimpleFunctionChecker>
|
||||||
get() = setOf(
|
get() = setOf(
|
||||||
|
FirJsTopLevelFunctionsChecker,
|
||||||
FirJsNativeInvokeChecker,
|
FirJsNativeInvokeChecker,
|
||||||
FirJsNativeGetterChecker,
|
FirJsNativeGetterChecker,
|
||||||
FirJsNativeSetterChecker,
|
FirJsNativeSetterChecker,
|
||||||
|
|||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* 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
@@ -52,4 +52,9 @@ object JvmDeclarationCheckers : DeclarationCheckers() {
|
|||||||
get() = setOf(
|
get() = setOf(
|
||||||
FirUpperBoundsChecker,
|
FirUpperBoundsChecker,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
override val simpleFunctionCheckers: Set<FirSimpleFunctionChecker>
|
||||||
|
get() = setOf(
|
||||||
|
FirJvmTopLevelFunctionsChecker,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* 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
@@ -54,7 +54,6 @@ object CommonDeclarationCheckers : DeclarationCheckers() {
|
|||||||
FirFunctionTypeParametersSyntaxChecker,
|
FirFunctionTypeParametersSyntaxChecker,
|
||||||
FirOperatorModifierChecker,
|
FirOperatorModifierChecker,
|
||||||
FirTailrecFunctionChecker,
|
FirTailrecFunctionChecker,
|
||||||
FirTopLevelFunctionsChecker,
|
|
||||||
FirMemberFunctionsChecker,
|
FirMemberFunctionsChecker,
|
||||||
FirDataObjectContentChecker,
|
FirDataObjectContentChecker,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -730,3 +730,6 @@ fun FirBasedSymbol<*>.hasAnnotationOrInsideAnnotatedClass(classId: ClassId, sess
|
|||||||
val container = getContainingClassSymbol(session) ?: return false
|
val container = getContainingClassSymbol(session) ?: return false
|
||||||
return container.hasAnnotationOrInsideAnnotatedClass(classId, session)
|
return container.hasAnnotationOrInsideAnnotatedClass(classId, session)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun FirDeclaration.hasAnnotationOrInsideAnnotatedClass(classId: ClassId, session: FirSession) =
|
||||||
|
symbol.hasAnnotationOrInsideAnnotatedClass(classId, session)
|
||||||
|
|||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* 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.checkers
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
||||||
|
|
||||||
|
interface FirPlatformDiagnosticSuppressor {
|
||||||
|
fun shouldReportNoBody(declaration: FirCallableDeclaration, context: CheckerContext): Boolean
|
||||||
|
|
||||||
|
object Default : FirPlatformDiagnosticSuppressor {
|
||||||
|
override fun shouldReportNoBody(declaration: FirCallableDeclaration, context: CheckerContext): Boolean = true
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-2
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
|||||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.checkers.FirPlatformDiagnosticSuppressor
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.hasModifier
|
import org.jetbrains.kotlin.fir.analysis.checkers.hasModifier
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||||
@@ -18,7 +19,9 @@ import org.jetbrains.kotlin.fir.declarations.utils.isExternal
|
|||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
|
|
||||||
// See old FE's [DeclarationsChecker]
|
// See old FE's [DeclarationsChecker]
|
||||||
object FirTopLevelFunctionsChecker : FirSimpleFunctionChecker() {
|
abstract class FirTopLevelFunctionsChecker : FirSimpleFunctionChecker() {
|
||||||
|
abstract val suppressor: FirPlatformDiagnosticSuppressor
|
||||||
|
|
||||||
override fun check(declaration: FirSimpleFunction, context: CheckerContext, reporter: DiagnosticReporter) {
|
override fun check(declaration: FirSimpleFunction, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
// Only report on top level callable declarations
|
// Only report on top level callable declarations
|
||||||
if (context.containingDeclarations.size > 1) return
|
if (context.containingDeclarations.size > 1) return
|
||||||
@@ -29,7 +32,7 @@ object FirTopLevelFunctionsChecker : FirSimpleFunctionChecker() {
|
|||||||
// So, our source of truth should be the full modifier list retrieved from the source.
|
// So, our source of truth should be the full modifier list retrieved from the source.
|
||||||
if (declaration.hasModifier(KtTokens.ABSTRACT_KEYWORD)) return
|
if (declaration.hasModifier(KtTokens.ABSTRACT_KEYWORD)) return
|
||||||
if (declaration.isExternal) return
|
if (declaration.isExternal) return
|
||||||
if (!declaration.hasBody && !declaration.isExpect) {
|
if (!declaration.hasBody && !declaration.isExpect && suppressor.shouldReportNoBody(declaration, context)) {
|
||||||
reporter.reportOn(source, FirErrors.NON_MEMBER_FUNCTION_NO_BODY, declaration.symbol, context)
|
reporter.reportOn(source, FirErrors.NON_MEMBER_FUNCTION_NO_BODY, declaration.symbol, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
// !DIAGNOSTICS: -DEPRECATION
|
|
||||||
<!NON_MEMBER_FUNCTION_NO_BODY!>@nativeGetter
|
|
||||||
fun String.foo(n: Int): Int?<!>
|
|
||||||
@nativeGetter
|
|
||||||
fun String.bar(n: Int): Int? = definedExternally
|
|
||||||
|
|
||||||
|
|
||||||
external interface T {
|
|
||||||
@nativeGetter
|
|
||||||
fun foo(d: Double): String?
|
|
||||||
@nativeGetter
|
|
||||||
fun bar(d: Double): String?
|
|
||||||
}
|
|
||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
// !DIAGNOSTICS: -DEPRECATION
|
// !DIAGNOSTICS: -DEPRECATION
|
||||||
@nativeGetter
|
@nativeGetter
|
||||||
fun String.foo(n: Int): Int?
|
fun String.foo(n: Int): Int?
|
||||||
|
|||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
// !DIAGNOSTICS: -DEPRECATION
|
|
||||||
<!NON_MEMBER_FUNCTION_NO_BODY!>@nativeInvoke
|
|
||||||
fun String.foo(): Int<!>
|
|
||||||
@nativeInvoke
|
|
||||||
fun String.bar(): Int = definedExternally
|
|
||||||
|
|
||||||
|
|
||||||
external object O {
|
|
||||||
@nativeInvoke
|
|
||||||
fun foo()
|
|
||||||
@nativeInvoke
|
|
||||||
fun bar() { definedExternally }
|
|
||||||
}
|
|
||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
// !DIAGNOSTICS: -DEPRECATION
|
// !DIAGNOSTICS: -DEPRECATION
|
||||||
@nativeInvoke
|
@nativeInvoke
|
||||||
fun String.foo(): Int
|
fun String.foo(): Int
|
||||||
|
|||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
// !DIAGNOSTICS: -DEPRECATION
|
|
||||||
<!NON_MEMBER_FUNCTION_NO_BODY!>@nativeSetter
|
|
||||||
fun String.foo(n: Int, v: Any)<!>
|
|
||||||
@nativeSetter
|
|
||||||
fun String.bar(n: Int, v: Any) {}
|
|
||||||
|
|
||||||
|
|
||||||
external class C {
|
|
||||||
@nativeSetter
|
|
||||||
fun foo(d: Double, v: Any): Any
|
|
||||||
@nativeSetter
|
|
||||||
fun bar(d: Double, v: Any): Any = definedExternally
|
|
||||||
}
|
|
||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
// !DIAGNOSTICS: -DEPRECATION
|
// !DIAGNOSTICS: -DEPRECATION
|
||||||
@nativeSetter
|
@nativeSetter
|
||||||
fun String.foo(n: Int, v: Any)
|
fun String.foo(n: Int, v: Any)
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ object JsStandardClassIds {
|
|||||||
val JsNativeSetter = "nativeSetter".jsId()
|
val JsNativeSetter = "nativeSetter".jsId()
|
||||||
|
|
||||||
val annotationsRequiringExternal = setOf(JsModule, JsQualifier)
|
val annotationsRequiringExternal = setOf(JsModule, JsQualifier)
|
||||||
|
|
||||||
|
val nativeAnnotations = setOf(JsNative, JsNativeInvoke, JsNativeGetter, JsNativeSetter)
|
||||||
}
|
}
|
||||||
|
|
||||||
object Callables {
|
object Callables {
|
||||||
|
|||||||
Reference in New Issue
Block a user