[Wasm] Port @JsFun checker to K2 (KT-56849)
^KT-62724 Fixed
This commit is contained in:
committed by
Space Team
parent
fbc35975ab
commit
31560217f8
+3
@@ -23,6 +23,9 @@ object FirWasmErrors {
|
||||
val CALL_TO_DEFINED_EXTERNALLY_FROM_NON_EXTERNAL_DECLARATION by error0<PsiElement>()
|
||||
val WRONG_JS_INTEROP_TYPE by error2<KtElement, String, ConeKotlinType>(SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT)
|
||||
|
||||
// JsFun
|
||||
val WRONG_JS_FUN_TARGET by error0<PsiElement>()
|
||||
|
||||
// Wasm interop
|
||||
val NESTED_WASM_EXPORT by error0<KtElement>()
|
||||
val WASM_EXPORT_ON_EXTERNAL_DECLARATION by error0<KtElement>()
|
||||
|
||||
+3
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.wasm.FirWasmErrors.WASM_IMP
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.wasm.FirWasmErrors.WASM_IMPORT_EXPORT_UNSUPPORTED_RETURN_TYPE
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.wasm.FirWasmErrors.WASM_IMPORT_EXPORT_VARARG_PARAMETER
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.wasm.FirWasmErrors.WASM_IMPORT_ON_NON_EXTERNAL_DECLARATION
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.wasm.FirWasmErrors.WRONG_JS_FUN_TARGET
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.wasm.FirWasmErrors.WRONG_JS_INTEROP_TYPE
|
||||
|
||||
@Suppress("unused")
|
||||
@@ -45,6 +46,8 @@ object FirWasmErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
|
||||
TO_STRING, FirDiagnosticRenderers.RENDER_TYPE,
|
||||
)
|
||||
|
||||
map.put(WRONG_JS_FUN_TARGET, "Only top-level external functions can be implemented using '@JsFun'.")
|
||||
|
||||
map.put(NESTED_WASM_EXPORT, "Only top-level functions can be exported with '@WasmExport'.")
|
||||
map.put(WASM_EXPORT_ON_EXTERNAL_DECLARATION, "Functions annotated with '@WasmExport' must not be external.")
|
||||
map.put(JS_AND_WASM_EXPORTS_ON_SAME_DECLARATION, "Cannot use '@WasmExport' and '@JsExport' for same function.")
|
||||
|
||||
+1
@@ -20,5 +20,6 @@ object WasmDeclarationCheckers : DeclarationCheckers() {
|
||||
FirWasmImportAnnotationChecker,
|
||||
FirWasmExportAnnotationChecker,
|
||||
FirWasmExternalChecker,
|
||||
FirWasmJsFunAnnotationChecker,
|
||||
)
|
||||
}
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.wasm.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirBasicDeclarationChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.isTopLevel
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.wasm.FirWasmErrors
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.getAnnotationByClassId
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isEffectivelyExternal
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.name.WasmStandardClassIds
|
||||
|
||||
object FirWasmJsFunAnnotationChecker : FirBasicDeclarationChecker() {
|
||||
override fun check(declaration: FirDeclaration, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
val annotation: FirAnnotation =
|
||||
declaration.annotations.getAnnotationByClassId(WasmStandardClassIds.Annotations.JsFun, context.session) ?: return
|
||||
|
||||
if (!context.isTopLevel || !declaration.symbol.isEffectivelyExternal(context.session)) {
|
||||
reporter.reportOn(annotation.source, FirWasmErrors.WRONG_JS_FUN_TARGET, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user