[Wasm/WASI] Allow external declarations only for top-level functions
Fix #KT-63737
This commit is contained in:
committed by
Space Team
parent
376a9b8ace
commit
ff20ae34e5
+7
-8
@@ -13,23 +13,22 @@ import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirBasicDeclaratio
|
|||||||
import org.jetbrains.kotlin.fir.analysis.checkers.isTopLevel
|
import org.jetbrains.kotlin.fir.analysis.checkers.isTopLevel
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.wasm.FirWasmErrors
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.wasm.FirWasmErrors
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||||
import org.jetbrains.kotlin.fir.declarations.hasAnnotation
|
import org.jetbrains.kotlin.fir.declarations.hasAnnotation
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.isEffectivelyExternal
|
import org.jetbrains.kotlin.fir.declarations.utils.isEffectivelyExternal
|
||||||
import org.jetbrains.kotlin.name.WasmStandardClassIds
|
import org.jetbrains.kotlin.name.WasmStandardClassIds
|
||||||
|
|
||||||
object FirWasmWasiExternalDeclarationChecker : FirBasicDeclarationChecker(MppCheckerKind.Common) {
|
object FirWasmWasiExternalDeclarationChecker : FirBasicDeclarationChecker(MppCheckerKind.Common) {
|
||||||
override fun check(declaration: FirDeclaration, context: CheckerContext, reporter: DiagnosticReporter) {
|
override fun check(declaration: FirDeclaration, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
|
if (!context.isTopLevel) return
|
||||||
if (!declaration.symbol.isEffectivelyExternal(context.session)) return
|
if (!declaration.symbol.isEffectivelyExternal(context.session)) return
|
||||||
|
|
||||||
if (declaration is FirSimpleFunction) {
|
if (declaration is FirFunction) {
|
||||||
if (!context.isTopLevel) {
|
if (!declaration.hasAnnotation(WasmStandardClassIds.Annotations.WasmImport, context.session)) {
|
||||||
reporter.reportOn(declaration.source, FirWasmErrors.WASI_EXTERNAL_NOT_TOP_LEVEL_FUNCTION, context)
|
reporter.reportOn(declaration.source, FirWasmErrors.WASI_EXTERNAL_FUNCTION_WITHOUT_IMPORT, context)
|
||||||
} else {
|
|
||||||
if (!declaration.hasAnnotation(WasmStandardClassIds.Annotations.WasmImport, context.session)) {
|
|
||||||
reporter.reportOn(declaration.source, FirWasmErrors.WASI_EXTERNAL_FUNCTION_WITHOUT_IMPORT, context)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
reporter.reportOn(declaration.source, FirWasmErrors.WASI_EXTERNAL_NOT_TOP_LEVEL_FUNCTION, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-3
@@ -3,9 +3,15 @@ import kotlin.wasm.WasmImport
|
|||||||
|
|
||||||
<!WASI_EXTERNAL_FUNCTION_WITHOUT_IMPORT!>external fun foo(): Int<!>
|
<!WASI_EXTERNAL_FUNCTION_WITHOUT_IMPORT!>external fun foo(): Int<!>
|
||||||
|
|
||||||
external interface I {
|
<!WASI_EXTERNAL_NOT_TOP_LEVEL_FUNCTION!>external interface I {
|
||||||
<!WASI_EXTERNAL_NOT_TOP_LEVEL_FUNCTION!>fun foo(): Int<!>
|
fun foo(): Int
|
||||||
}
|
}<!>
|
||||||
|
|
||||||
|
<!WASI_EXTERNAL_NOT_TOP_LEVEL_FUNCTION!>external class X<!>
|
||||||
|
|
||||||
|
<!WASI_EXTERNAL_NOT_TOP_LEVEL_FUNCTION!>external val v: Int<!>
|
||||||
|
|
||||||
|
external <!WASI_EXTERNAL_NOT_TOP_LEVEL_FUNCTION!>object AC<!>
|
||||||
|
|
||||||
@WasmImport("a", "b")
|
@WasmImport("a", "b")
|
||||||
external fun importedFoo(): Int
|
external fun importedFoo(): Int
|
||||||
|
|||||||
+8
-7
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.wasm.resolve.diagnostics
|
|||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.MemberDescriptor
|
import org.jetbrains.kotlin.descriptors.MemberDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
||||||
import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi
|
import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
@@ -19,18 +20,18 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
|||||||
object WasmWasiExternalDeclarationChecker : DeclarationChecker {
|
object WasmWasiExternalDeclarationChecker : DeclarationChecker {
|
||||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
||||||
if (descriptor !is MemberDescriptor) return
|
if (descriptor !is MemberDescriptor) return
|
||||||
|
if (descriptor is PropertyAccessorDescriptor) return
|
||||||
|
if (!DescriptorUtils.isTopLevelDeclaration(descriptor)) return
|
||||||
if (!descriptor.isEffectivelyExternal()) return
|
if (!descriptor.isEffectivelyExternal()) return
|
||||||
|
|
||||||
if (descriptor is FunctionDescriptor) {
|
if (descriptor is FunctionDescriptor) {
|
||||||
if (!DescriptorUtils.isTopLevelDeclaration(descriptor)) {
|
if (!descriptor.annotations.hasAnnotation(FqName("kotlin.wasm.WasmImport"))) {
|
||||||
val reportOn = descriptor.findPsi() ?: declaration
|
val reportOn = descriptor.findPsi() ?: declaration
|
||||||
context.trace.report(ErrorsWasm.WASI_EXTERNAL_NOT_TOP_LEVEL_FUNCTION.on(reportOn))
|
context.trace.report(ErrorsWasm.WASI_EXTERNAL_FUNCTION_WITHOUT_IMPORT.on(reportOn))
|
||||||
} else {
|
|
||||||
if (!descriptor.annotations.hasAnnotation(FqName("kotlin.wasm.WasmImport"))) {
|
|
||||||
val reportOn = descriptor.findPsi() ?: declaration
|
|
||||||
context.trace.report(ErrorsWasm.WASI_EXTERNAL_FUNCTION_WITHOUT_IMPORT.on(reportOn))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
val reportOn = descriptor.findPsi() ?: declaration
|
||||||
|
context.trace.report(ErrorsWasm.WASI_EXTERNAL_NOT_TOP_LEVEL_FUNCTION.on(reportOn))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user