diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt index 237892459a9..8184c4c1151 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt @@ -4685,6 +4685,109 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert token, ) } + add(FirJsErrors.EXTERNAL_CLASS_CONSTRUCTOR_PROPERTY_PARAMETER) { firDiagnostic -> + ExternalClassConstructorPropertyParameterImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } + add(FirJsErrors.EXTERNAL_ENUM_ENTRY_WITH_BODY) { firDiagnostic -> + ExternalEnumEntryWithBodyImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } + add(FirJsErrors.EXTERNAL_ANONYMOUS_INITIALIZER) { firDiagnostic -> + ExternalAnonymousInitializerImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } + add(FirJsErrors.EXTERNAL_DELEGATION) { firDiagnostic -> + ExternalDelegationImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } + add(FirJsErrors.EXTERNAL_DELEGATED_CONSTRUCTOR_CALL) { firDiagnostic -> + ExternalDelegatedConstructorCallImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } + add(FirJsErrors.WRONG_BODY_OF_EXTERNAL_DECLARATION) { firDiagnostic -> + WrongBodyOfExternalDeclarationImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } + add(FirJsErrors.WRONG_INITIALIZER_OF_EXTERNAL_DECLARATION) { firDiagnostic -> + WrongInitializerOfExternalDeclarationImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } + add(FirJsErrors.WRONG_DEFAULT_VALUE_FOR_EXTERNAL_FUN_PARAMETER) { firDiagnostic -> + WrongDefaultValueForExternalFunParameterImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } + add(FirJsErrors.NESTED_EXTERNAL_DECLARATION) { firDiagnostic -> + NestedExternalDeclarationImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } + add(FirJsErrors.WRONG_EXTERNAL_DECLARATION) { firDiagnostic -> + WrongExternalDeclarationImpl( + firDiagnostic.a, + firDiagnostic as KtPsiDiagnostic, + token, + ) + } + add(FirJsErrors.NESTED_CLASS_IN_EXTERNAL_INTERFACE) { firDiagnostic -> + NestedClassInExternalInterfaceImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } + add(FirJsErrors.EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE) { firDiagnostic -> + ExternalTypeExtendsNonExternalTypeImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } + add(FirJsErrors.INLINE_EXTERNAL_DECLARATION) { firDiagnostic -> + InlineExternalDeclarationImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } + add(FirJsErrors.INLINE_CLASS_IN_EXTERNAL_DECLARATION_WARNING) { firDiagnostic -> + InlineClassInExternalDeclarationWarningImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } + add(FirJsErrors.INLINE_CLASS_IN_EXTERNAL_DECLARATION) { firDiagnostic -> + InlineClassInExternalDeclarationImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } + add(FirJsErrors.EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION) { firDiagnostic -> + ExtensionFunctionInExternalDeclarationImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } + add(FirJsErrors.NON_ABSTRACT_MEMBER_OF_EXTERNAL_INTERFACE) { firDiagnostic -> + NonAbstractMemberOfExternalInterfaceImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } add(FirJsErrors.DELEGATION_BY_DYNAMIC) { firDiagnostic -> DelegationByDynamicImpl( firDiagnostic as KtPsiDiagnostic, diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt index 353b5bc165f..503752ac83f 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt @@ -3258,6 +3258,75 @@ sealed class KtFirDiagnostic : KtDiagnosticWithPsi { override val diagnosticClass get() = CallToDefinedExternallyFromNonExternalDeclaration::class } + abstract class ExternalClassConstructorPropertyParameter : KtFirDiagnostic() { + override val diagnosticClass get() = ExternalClassConstructorPropertyParameter::class + } + + abstract class ExternalEnumEntryWithBody : KtFirDiagnostic() { + override val diagnosticClass get() = ExternalEnumEntryWithBody::class + } + + abstract class ExternalAnonymousInitializer : KtFirDiagnostic() { + override val diagnosticClass get() = ExternalAnonymousInitializer::class + } + + abstract class ExternalDelegation : KtFirDiagnostic() { + override val diagnosticClass get() = ExternalDelegation::class + } + + abstract class ExternalDelegatedConstructorCall : KtFirDiagnostic() { + override val diagnosticClass get() = ExternalDelegatedConstructorCall::class + } + + abstract class WrongBodyOfExternalDeclaration : KtFirDiagnostic() { + override val diagnosticClass get() = WrongBodyOfExternalDeclaration::class + } + + abstract class WrongInitializerOfExternalDeclaration : KtFirDiagnostic() { + override val diagnosticClass get() = WrongInitializerOfExternalDeclaration::class + } + + abstract class WrongDefaultValueForExternalFunParameter : KtFirDiagnostic() { + override val diagnosticClass get() = WrongDefaultValueForExternalFunParameter::class + } + + abstract class NestedExternalDeclaration : KtFirDiagnostic() { + override val diagnosticClass get() = NestedExternalDeclaration::class + } + + abstract class WrongExternalDeclaration : KtFirDiagnostic() { + override val diagnosticClass get() = WrongExternalDeclaration::class + abstract val classKind: String + } + + abstract class NestedClassInExternalInterface : KtFirDiagnostic() { + override val diagnosticClass get() = NestedClassInExternalInterface::class + } + + abstract class ExternalTypeExtendsNonExternalType : KtFirDiagnostic() { + override val diagnosticClass get() = ExternalTypeExtendsNonExternalType::class + } + + abstract class InlineExternalDeclaration : KtFirDiagnostic() { + override val diagnosticClass get() = InlineExternalDeclaration::class + } + + abstract class InlineClassInExternalDeclarationWarning : KtFirDiagnostic() { + override val diagnosticClass get() = InlineClassInExternalDeclarationWarning::class + } + + abstract class InlineClassInExternalDeclaration : KtFirDiagnostic() { + override val diagnosticClass get() = InlineClassInExternalDeclaration::class + } + + abstract class ExtensionFunctionInExternalDeclaration : KtFirDiagnostic() { + override val diagnosticClass get() = ExtensionFunctionInExternalDeclaration::class + } + + abstract class NonAbstractMemberOfExternalInterface : KtFirDiagnostic() { + override val diagnosticClass get() = NonAbstractMemberOfExternalInterface::class + } + abstract class DelegationByDynamic : KtFirDiagnostic() { override val diagnosticClass get() = DelegationByDynamic::class } diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt index 264a2f14688..0718c270647 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt @@ -3942,6 +3942,92 @@ internal class CallToDefinedExternallyFromNonExternalDeclarationImpl( override val token: KtLifetimeToken, ) : KtFirDiagnostic.CallToDefinedExternallyFromNonExternalDeclaration(), KtAbstractFirDiagnostic +internal class ExternalClassConstructorPropertyParameterImpl( + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.ExternalClassConstructorPropertyParameter(), KtAbstractFirDiagnostic + +internal class ExternalEnumEntryWithBodyImpl( + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.ExternalEnumEntryWithBody(), KtAbstractFirDiagnostic + +internal class ExternalAnonymousInitializerImpl( + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.ExternalAnonymousInitializer(), KtAbstractFirDiagnostic + +internal class ExternalDelegationImpl( + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.ExternalDelegation(), KtAbstractFirDiagnostic + +internal class ExternalDelegatedConstructorCallImpl( + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.ExternalDelegatedConstructorCall(), KtAbstractFirDiagnostic + +internal class WrongBodyOfExternalDeclarationImpl( + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.WrongBodyOfExternalDeclaration(), KtAbstractFirDiagnostic + +internal class WrongInitializerOfExternalDeclarationImpl( + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.WrongInitializerOfExternalDeclaration(), KtAbstractFirDiagnostic + +internal class WrongDefaultValueForExternalFunParameterImpl( + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.WrongDefaultValueForExternalFunParameter(), KtAbstractFirDiagnostic + +internal class NestedExternalDeclarationImpl( + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.NestedExternalDeclaration(), KtAbstractFirDiagnostic + +internal class WrongExternalDeclarationImpl( + override val classKind: String, + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.WrongExternalDeclaration(), KtAbstractFirDiagnostic + +internal class NestedClassInExternalInterfaceImpl( + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.NestedClassInExternalInterface(), KtAbstractFirDiagnostic + +internal class ExternalTypeExtendsNonExternalTypeImpl( + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.ExternalTypeExtendsNonExternalType(), KtAbstractFirDiagnostic + +internal class InlineExternalDeclarationImpl( + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.InlineExternalDeclaration(), KtAbstractFirDiagnostic + +internal class InlineClassInExternalDeclarationWarningImpl( + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.InlineClassInExternalDeclarationWarning(), KtAbstractFirDiagnostic + +internal class InlineClassInExternalDeclarationImpl( + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.InlineClassInExternalDeclaration(), KtAbstractFirDiagnostic + +internal class ExtensionFunctionInExternalDeclarationImpl( + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.ExtensionFunctionInExternalDeclaration(), KtAbstractFirDiagnostic + +internal class NonAbstractMemberOfExternalInterfaceImpl( + override val firDiagnostic: KtPsiDiagnostic, + override val token: KtLifetimeToken, +) : KtFirDiagnostic.NonAbstractMemberOfExternalInterface(), KtAbstractFirDiagnostic + internal class DelegationByDynamicImpl( override val firDiagnostic: KtPsiDiagnostic, override val token: KtLifetimeToken, diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirJsDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirJsDiagnosticsList.kt index c3d4baf2c93..d75eed04e96 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirJsDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirJsDiagnosticsList.kt @@ -11,8 +11,7 @@ import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.DiagnosticL import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.PositioningStrategy import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol -import org.jetbrains.kotlin.psi.KtClassOrObject -import org.jetbrains.kotlin.psi.KtElement +import org.jetbrains.kotlin.psi.* @Suppress("UNUSED_VARIABLE", "LocalVariableName", "ClassName", "unused") @OptIn(PrivateForInline::class) @@ -42,6 +41,25 @@ object JS_DIAGNOSTICS_LIST : DiagnosticList("FirJsErrors") { parameter("function") } val CALL_TO_DEFINED_EXTERNALLY_FROM_NON_EXTERNAL_DECLARATION by error() + val EXTERNAL_CLASS_CONSTRUCTOR_PROPERTY_PARAMETER by error() + val EXTERNAL_ENUM_ENTRY_WITH_BODY by error() + val EXTERNAL_ANONYMOUS_INITIALIZER by error() + val EXTERNAL_DELEGATION by error() + val EXTERNAL_DELEGATED_CONSTRUCTOR_CALL by error() + val WRONG_BODY_OF_EXTERNAL_DECLARATION by error() + val WRONG_INITIALIZER_OF_EXTERNAL_DECLARATION by error() + val WRONG_DEFAULT_VALUE_FOR_EXTERNAL_FUN_PARAMETER by error() + val NESTED_EXTERNAL_DECLARATION by error(PositioningStrategy.DECLARATION_SIGNATURE_OR_DEFAULT) + val WRONG_EXTERNAL_DECLARATION by error(PositioningStrategy.DECLARATION_SIGNATURE_OR_DEFAULT) { + parameter("classKind") + } + val NESTED_CLASS_IN_EXTERNAL_INTERFACE by error(PositioningStrategy.DECLARATION_SIGNATURE_OR_DEFAULT) + val EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE by error(PositioningStrategy.DECLARATION_SIGNATURE_OR_DEFAULT) + val INLINE_EXTERNAL_DECLARATION by error(PositioningStrategy.DECLARATION_SIGNATURE_OR_DEFAULT) + val INLINE_CLASS_IN_EXTERNAL_DECLARATION_WARNING by warning(PositioningStrategy.DECLARATION_SIGNATURE_OR_DEFAULT) + val INLINE_CLASS_IN_EXTERNAL_DECLARATION by error(PositioningStrategy.DECLARATION_SIGNATURE_OR_DEFAULT) + val EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION by error(PositioningStrategy.DECLARATION_SIGNATURE_OR_DEFAULT) + val NON_ABSTRACT_MEMBER_OF_EXTERNAL_INTERFACE by error(PositioningStrategy.DECLARATION_SIGNATURE_OR_DEFAULT) } val DYNAMICS by object : DiagnosticGroup("Dynamics") { diff --git a/compiler/fir/checkers/checkers.js/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/js/FirJsErrors.kt b/compiler/fir/checkers/checkers.js/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/js/FirJsErrors.kt index 5e65eabd5e9..8b9a08d5fc9 100644 --- a/compiler/fir/checkers/checkers.js/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/js/FirJsErrors.kt +++ b/compiler/fir/checkers/checkers.js/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/js/FirJsErrors.kt @@ -12,8 +12,12 @@ import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory import org.jetbrains.kotlin.fir.analysis.diagnostics.* import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol +import org.jetbrains.kotlin.psi.KtAnonymousInitializer import org.jetbrains.kotlin.psi.KtClassOrObject +import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtElement +import org.jetbrains.kotlin.psi.KtExpression +import org.jetbrains.kotlin.psi.KtParameter /* * This file was generated automatically @@ -39,6 +43,23 @@ object FirJsErrors { val OVERRIDING_EXTERNAL_FUN_WITH_OPTIONAL_PARAMS by error0(SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT) val OVERRIDING_EXTERNAL_FUN_WITH_OPTIONAL_PARAMS_WITH_FAKE by error1(SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT) val CALL_TO_DEFINED_EXTERNALLY_FROM_NON_EXTERNAL_DECLARATION by error0() + val EXTERNAL_CLASS_CONSTRUCTOR_PROPERTY_PARAMETER by error0() + val EXTERNAL_ENUM_ENTRY_WITH_BODY by error0() + val EXTERNAL_ANONYMOUS_INITIALIZER by error0() + val EXTERNAL_DELEGATION by error0() + val EXTERNAL_DELEGATED_CONSTRUCTOR_CALL by error0() + val WRONG_BODY_OF_EXTERNAL_DECLARATION by error0() + val WRONG_INITIALIZER_OF_EXTERNAL_DECLARATION by error0() + val WRONG_DEFAULT_VALUE_FOR_EXTERNAL_FUN_PARAMETER by error0() + val NESTED_EXTERNAL_DECLARATION by error0(SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT) + val WRONG_EXTERNAL_DECLARATION by error1(SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT) + val NESTED_CLASS_IN_EXTERNAL_INTERFACE by error0(SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT) + val EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE by error0(SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT) + val INLINE_EXTERNAL_DECLARATION by error0(SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT) + val INLINE_CLASS_IN_EXTERNAL_DECLARATION_WARNING by warning0(SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT) + val INLINE_CLASS_IN_EXTERNAL_DECLARATION by error0(SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT) + val EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION by error0(SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT) + val NON_ABSTRACT_MEMBER_OF_EXTERNAL_INTERFACE by error0(SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT) // Dynamics val DELEGATION_BY_DYNAMIC by error0() diff --git a/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/diagnostics/js/FirJsErrorsDefaultMessages.kt b/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/diagnostics/js/FirJsErrorsDefaultMessages.kt index 25d75b68284..3700b310ae8 100644 --- a/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/diagnostics/js/FirJsErrorsDefaultMessages.kt +++ b/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/diagnostics/js/FirJsErrorsDefaultMessages.kt @@ -7,18 +7,36 @@ package org.jetbrains.kotlin.fir.analysis.diagnostics.js import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory +import org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers import org.jetbrains.kotlin.fir.analysis.diagnostics.checkMissingMessages import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.CALL_TO_DEFINED_EXTERNALLY_FROM_NON_EXTERNAL_DECLARATION +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.EXTERNAL_ANONYMOUS_INITIALIZER +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.EXTERNAL_CLASS_CONSTRUCTOR_PROPERTY_PARAMETER +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.EXTERNAL_DELEGATED_CONSTRUCTOR_CALL +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.EXTERNAL_DELEGATION +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.EXTERNAL_ENUM_ENTRY_WITH_BODY +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.DELEGATION_BY_DYNAMIC import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.IMPLEMENTING_FUNCTION_INTERFACE +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.INLINE_CLASS_IN_EXTERNAL_DECLARATION +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.INLINE_CLASS_IN_EXTERNAL_DECLARATION_WARNING +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.INLINE_EXTERNAL_DECLARATION import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.JS_MODULE_PROHIBITED_ON_NON_NATIVE import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.JS_MODULE_PROHIBITED_ON_VAR import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.NESTED_JS_MODULE_PROHIBITED +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.NESTED_CLASS_IN_EXTERNAL_INTERFACE +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.NESTED_EXTERNAL_DECLARATION +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.NON_ABSTRACT_MEMBER_OF_EXTERNAL_INTERFACE import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.OVERRIDING_EXTERNAL_FUN_WITH_OPTIONAL_PARAMS import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.OVERRIDING_EXTERNAL_FUN_WITH_OPTIONAL_PARAMS_WITH_FAKE import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.RUNTIME_ANNOTATION_NOT_SUPPORTED import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.RUNTIME_ANNOTATION_ON_EXTERNAL_DECLARATION +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.WRONG_BODY_OF_EXTERNAL_DECLARATION +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.WRONG_DEFAULT_VALUE_FOR_EXTERNAL_FUN_PARAMETER +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.WRONG_EXTERNAL_DECLARATION +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.WRONG_INITIALIZER_OF_EXTERNAL_DECLARATION import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.WRONG_JS_QUALIFIER import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors.WRONG_MULTIPLE_INHERITANCE @@ -51,6 +69,38 @@ object FirJsErrorsDefaultMessages : BaseDiagnosticRendererFactory() { RUNTIME_ANNOTATION_NOT_SUPPORTED, "Reflection is not supported in JavaScript target, therefore you won't be able to read this annotation in run-time" ) + map.put(EXTERNAL_CLASS_CONSTRUCTOR_PROPERTY_PARAMETER, "External class constructor cannot have a property parameter") + map.put(EXTERNAL_ENUM_ENTRY_WITH_BODY, "Entry of external enum class can't have body") + map.put(EXTERNAL_ANONYMOUS_INITIALIZER, "Anonymous initializer is not allowed in external classes") + map.put(EXTERNAL_DELEGATION, "Can't use delegate on external declaration") + map.put(EXTERNAL_DELEGATED_CONSTRUCTOR_CALL, "Delegated constructor call in external class is not allowed") + map.put( + WRONG_BODY_OF_EXTERNAL_DECLARATION, + "Wrong body of external declaration. Must be either ' = definedExternally' or { definedExternally }" + ) + map.put(WRONG_INITIALIZER_OF_EXTERNAL_DECLARATION, "Wrong initializer of external declaration. Must be ' = definedExternally'") + map.put( + WRONG_DEFAULT_VALUE_FOR_EXTERNAL_FUN_PARAMETER, + "Wrong default value for parameter of external function. Must be ' = definedExternally'" + ) + map.put(NESTED_EXTERNAL_DECLARATION, "Non top-level `external` declaration") + map.put(WRONG_EXTERNAL_DECLARATION, "Declaration of such kind ({0}) can''t be external", CommonRenderers.STRING) + map.put(NESTED_CLASS_IN_EXTERNAL_INTERFACE, "Interface can't contain nested classes and objects") + map.put(EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE, "External type extends non-external type") + map.put(INLINE_EXTERNAL_DECLARATION, "Inline external declaration") + map.put( + INLINE_CLASS_IN_EXTERNAL_DECLARATION_WARNING, + "Using value classes as parameter type or return type of external declarations is experimental" + ) + map.put( + INLINE_CLASS_IN_EXTERNAL_DECLARATION, + "Using value classes as parameter type or return type of external declarations is not supported" + ) + map.put(EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION, "Function types with receiver are prohibited in external declarations") + map.put( + NON_ABSTRACT_MEMBER_OF_EXTERNAL_INTERFACE, + "Only nullable properties of external interfaces are allowed to be non-abstract" + ) map.checkMissingMessages(FirJsErrors) } diff --git a/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/js/checkers/JsDeclarationCheckers.kt b/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/js/checkers/JsDeclarationCheckers.kt index 3e3526e0dfe..2ea9ea665bb 100644 --- a/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/js/checkers/JsDeclarationCheckers.kt +++ b/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/js/checkers/JsDeclarationCheckers.kt @@ -24,6 +24,7 @@ object JsDeclarationCheckers : DeclarationCheckers() { get() = setOf( FirJsModuleChecker, FirJsRuntimeAnnotationChecker, + FirJsExternalChecker, ) override val classCheckers: Set diff --git a/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/js/checkers/declaration/FirJsExternalChecker.kt b/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/js/checkers/declaration/FirJsExternalChecker.kt new file mode 100644 index 00000000000..6294874a9fe --- /dev/null +++ b/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/js/checkers/declaration/FirJsExternalChecker.kt @@ -0,0 +1,348 @@ +/* + * 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.* +import org.jetbrains.kotlin.builtins.StandardNames +import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.descriptors.ClassKind +import org.jetbrains.kotlin.descriptors.Modality +import org.jetbrains.kotlin.descriptors.Visibilities +import org.jetbrains.kotlin.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactory0 +import org.jetbrains.kotlin.diagnostics.reportOn +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.analysis.checkers.* +import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirBasicDeclarationChecker +import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors +import org.jetbrains.kotlin.fir.analysis.js.checkers.isEffectivelyExternal +import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor +import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyBackingField +import org.jetbrains.kotlin.fir.declarations.impl.FirPrimaryConstructor +import org.jetbrains.kotlin.fir.declarations.utils.* +import org.jetbrains.kotlin.fir.expressions.FirPropertyAccessExpression +import org.jetbrains.kotlin.fir.expressions.FirReturnExpression +import org.jetbrains.kotlin.fir.expressions.impl.FirSingleExpressionBlock +import org.jetbrains.kotlin.fir.analysis.js.checkers.isNativeObject +import org.jetbrains.kotlin.fir.references.toResolvedPropertySymbol +import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol +import org.jetbrains.kotlin.fir.types.* +import org.jetbrains.kotlin.lexer.KtTokens +import org.jetbrains.kotlin.name.JsStandardClassIds +import org.jetbrains.kotlin.name.JsStandardClassIds.Annotations.JsNative +import org.jetbrains.kotlin.psi.KtParameter +import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull + +object FirJsExternalChecker : FirBasicDeclarationChecker() { + override fun check(declaration: FirDeclaration, context: CheckerContext, reporter: DiagnosticReporter) { + if (!declaration.symbol.isNativeObject(context)) return + + if (!context.isTopLevel) { + if (declaration !is FirPropertyAccessor && declaration.isDirectlyExternal(context.session)) { + reporter.reportOn(declaration.source, FirJsErrors.NESTED_EXTERNAL_DECLARATION, context) + } + } + + if (declaration is FirClass) { + // TODO: KT-55600: Stop generating diagnostic + // messages inside checkers + val classKind = when { + declaration.status.isData -> "data class" + declaration.status.isInner -> "inner class" + declaration.status.isInline -> "value class" + declaration.status.isFun -> "fun interface" + declaration.classKind == ClassKind.ANNOTATION_CLASS -> "annotation class" + else -> null + } + + if (classKind != null) { + reporter.reportOn(declaration.source, FirJsErrors.WRONG_EXTERNAL_DECLARATION, classKind, context) + } + } + + if (declaration is FirPropertyAccessor && declaration.isDirectlyExternal(context.session)) { + reporter.reportOn(declaration.source, FirJsErrors.WRONG_EXTERNAL_DECLARATION, "property accessor", context) + } else if (declaration !is FirPrimaryConstructor && declaration.isPrivateMemberOfExternalClass(context.session)) { + reporter.reportOn(declaration.source, FirJsErrors.WRONG_EXTERNAL_DECLARATION, "private member of class", context) + } + + val container = context.containingDeclarations.lastOrNull() + + if ( + declaration is FirClass && + declaration.classKind != ClassKind.INTERFACE && + container is FirClass && container.classKind == ClassKind.INTERFACE + ) { + reporter.reportOn(declaration.source, FirJsErrors.NESTED_CLASS_IN_EXTERNAL_INTERFACE, context) + } + + if (declaration !is FirPropertyAccessor && declaration is FirCallableDeclaration && declaration.isExtension) { + val target = when (declaration) { + is FirFunction -> "extension function" + is FirProperty -> "extension property" + else -> "extension member" + } + reporter.reportOn(declaration.source, FirJsErrors.WRONG_EXTERNAL_DECLARATION, target, context) + } + + if (declaration is FirClass && declaration.classKind != ClassKind.ANNOTATION_CLASS) { + val superClasses = declaration.superInterfaces(context.session).toMutableList() + declaration.superClassNotAny(context.session)?.let { + superClasses.add(it) + } + if (declaration.classKind == ClassKind.ENUM_CLASS || declaration.classKind == ClassKind.ENUM_ENTRY) { + superClasses.removeAll { it.classId?.asSingleFqName()?.toUnsafe() == StandardNames.FqNames._enum } + } + val superDeclarations = superClasses.mapNotNull { it.toSymbol(context.session) } + if (superDeclarations.any { !it.isNativeObject(context) && it.classId.asSingleFqName() != StandardNames.FqNames.throwable }) { + reporter.reportOn(declaration.source, FirJsErrors.EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE, context) + } + } + + if (declaration is FirFunction && declaration.isInline) { + reporter.reportOn(declaration.source, FirJsErrors.INLINE_EXTERNAL_DECLARATION, context) + } + + fun reportOnParametersAndReturnTypesIf( + diagnosticFactory: KtDiagnosticFactory0, + condition: (ConeKotlinType) -> Boolean, + ) { + if ( + declaration !is FirCallableDeclaration || + declaration is FirDefaultPropertyAccessor || + declaration is FirDefaultPropertyBackingField + ) { + return + } + + fun checkTypeIsNotInlineClass(type: ConeKotlinType, elementToReport: KtSourceElement?) { + if (condition(type)) { + reporter.reportOn(elementToReport, diagnosticFactory, context) + } + } + + if (declaration.returnTypeRef.source?.allowsReporting == true) { + declaration.returnTypeRef.source?.let { + checkTypeIsNotInlineClass(declaration.returnTypeRef.coneType, it) + } + } + + if (declaration !is FirFunction) { + return + } + + for (parameter in declaration.valueParameters) { + val ktParam = if (parameter.source?.psi is KtParameter) { + parameter.source + } else { + declaration.source + } + + if (ktParam?.allowsReporting != true) { + continue + } + + val typeToCheck = parameter.varargElementType ?: parameter.returnTypeRef.coneType + checkTypeIsNotInlineClass(typeToCheck, ktParam) + } + } + + val valueClassInExternalDiagnostic = when { + context.languageVersionSettings.supportsFeature(LanguageFeature.JsAllowValueClassesInExternals) -> { + FirJsErrors.INLINE_CLASS_IN_EXTERNAL_DECLARATION_WARNING + } + + else -> { + FirJsErrors.INLINE_CLASS_IN_EXTERNAL_DECLARATION + } + } + + reportOnParametersAndReturnTypesIf(valueClassInExternalDiagnostic) { it.isValueClass(context.session) } + + if (!context.languageVersionSettings.supportsFeature(LanguageFeature.JsEnableExtensionFunctionInExternals)) { + reportOnParametersAndReturnTypesIf( + FirJsErrors.EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION, ConeKotlinType::isExtensionFunctionType + ) + } + + if ( + declaration is FirCallableDeclaration && + declaration.isNonAbstractMemberIfInterface(context.session) && + !declaration.isNullableProperty() + ) { + reporter.reportOn(declaration.source, FirJsErrors.NON_ABSTRACT_MEMBER_OF_EXTERNAL_INTERFACE, context) + } + + declaration.checkBody(context, reporter) + declaration.checkDelegation(context, reporter) + declaration.checkAnonymousInitializer(context, reporter) + declaration.checkEnumEntry(context, reporter) + declaration.checkConstructorPropertyParam(context, reporter) + } + + private val KtSourceElement.allowsReporting + get() = kind !is KtFakeSourceElementKind || kind == KtFakeSourceElementKind.PropertyFromParameter + + private val FirValueParameter.varargElementType + get() = when { + !isVararg -> null + else -> returnTypeRef.coneType.typeArguments.firstOrNull()?.type + } + + private fun FirClass.superClassNotAny(session: FirSession) = superConeTypes + .filterNot { it.isAny || it.isNullableAny } + .find { it.toSymbol(session)?.classKind == ClassKind.CLASS } + + private fun FirClass.superInterfaces(session: FirSession) = superConeTypes + .filterNot { it.isAny || it.isNullableAny } + .filter { it.toSymbol(session)?.classKind == ClassKind.INTERFACE } + + private fun FirDeclaration.checkBody(context: CheckerContext, reporter: DiagnosticReporter) { + if (this is FirDefaultPropertyAccessor) return + + val body = when (this) { + is FirFunction -> body + is FirAnonymousInitializer -> body + else -> null + } + + val initializer = when { + this is FirEnumEntry -> null + source?.kind == KtFakeSourceElementKind.PropertyFromParameter -> null + this is FirVariable -> initializer + body is FirSingleExpressionBlock -> (body.statement as? FirReturnExpression)?.result + else -> null + } + + val isWrong = body !is FirSingleExpressionBlock && !hasValidExternalBody() + || initializer != null && !initializer.isDefinedExternallyExpression() + + if (isWrong && body != null) { + reporter.reportOn(body.source, FirJsErrors.WRONG_BODY_OF_EXTERNAL_DECLARATION, context) + } else if (isWrong && initializer != null) { + reporter.reportOn(initializer.source, FirJsErrors.WRONG_INITIALIZER_OF_EXTERNAL_DECLARATION, context) + } + + // we shouldn't check such things as the + // copy() function of a data class + if (source?.kind !is KtRealSourceElementKind) { + return + } + + if (this is FirFunction) { + for (defaultValue in valueParameters.mapNotNull { it.defaultValue }) { + if (!defaultValue.isDefinedExternallyExpression()) { + reporter.reportOn(defaultValue.source, FirJsErrors.WRONG_DEFAULT_VALUE_FOR_EXTERNAL_FUN_PARAMETER, context) + } + } + } + } + + private fun FirDeclaration.checkDelegation(context: CheckerContext, reporter: DiagnosticReporter) { + if (this !is FirMemberDeclaration || !symbol.isEffectivelyExternal(context)) return + + if (this is FirClass) { + declarations.firstIsInstanceOrNull()?.let { + val constructorCall = it.delegatedConstructor + + if (constructorCall?.source?.kind is KtRealSourceElementKind) { + reporter.reportOn(constructorCall.source, FirJsErrors.EXTERNAL_DELEGATED_CONSTRUCTOR_CALL, context) + } + } + + for ((superType, delegate) in collectSupertypesWithDelegates()) { + when { + delegate != null -> { + reporter.reportOn(superType.source, FirJsErrors.EXTERNAL_DELEGATION, context) + } + } + } + } else if (this is FirConstructor && !isPrimary) { + val delegationCall = delegatedConstructor + + if (delegationCall?.source?.kind is KtRealSourceElementKind) { + reporter.reportOn(delegationCall.source, FirJsErrors.EXTERNAL_DELEGATED_CONSTRUCTOR_CALL, context) + } + } else if (this is FirProperty) { + delegate?.let { + reporter.reportOn(it.source, FirJsErrors.EXTERNAL_DELEGATION, context) + } + } + } + + private fun FirDeclaration.checkAnonymousInitializer(context: CheckerContext, reporter: DiagnosticReporter) { + if (this !is FirClass) return + + for (anonymousInitializer in anonymousInitializers) { + reporter.reportOn(anonymousInitializer.source, FirJsErrors.EXTERNAL_ANONYMOUS_INITIALIZER, context) + } + } + + private fun FirDeclaration.checkEnumEntry(context: CheckerContext, reporter: DiagnosticReporter) { + if (this !is FirEnumEntry) return + initializer?.let { + reporter.reportOn(it.source, FirJsErrors.EXTERNAL_ENUM_ENTRY_WITH_BODY, context) + } + } + + private fun FirDeclaration.checkConstructorPropertyParam(context: CheckerContext, reporter: DiagnosticReporter) { + if (this !is FirProperty || source?.kind != KtFakeSourceElementKind.PropertyFromParameter) return + val containingClass = getContainingClassSymbol(context.session) as? FirClassSymbol<*> ?: return + if (containingClass.isData || containingClass.classKind == ClassKind.ANNOTATION_CLASS) return + reporter.reportOn(source, FirJsErrors.EXTERNAL_CLASS_CONSTRUCTOR_PROPERTY_PARAMETER, context) + } + + private fun FirDeclaration.isDirectlyExternal(session: FirSession): Boolean { + // source kind is checked, otherwise this function + // may return true for a primary constructor of an external class + if (this is FirDefaultPropertyAccessor || this.source?.kind !is KtRealSourceElementKind) return false + return hasModifier(KtTokens.EXTERNAL_KEYWORD) || hasAnnotation(JsNative, session) + } + + private fun FirDeclaration.isPrivateMemberOfExternalClass(session: FirSession): Boolean { + if (this is FirPropertyAccessor && visibility == propertySymbol.visibility) return false + if (this !is FirMemberDeclaration || visibility != Visibilities.Private) return false + + val containingDeclaration = getContainingClassSymbol(session) ?: return false + return containingDeclaration.isNativeObject(session) + } + + private fun FirDeclaration.isNonAbstractMemberIfInterface(session: FirSession): Boolean { + return this is FirCallableDeclaration + && modality != Modality.ABSTRACT + && (getContainingClassSymbol(session) as? FirClassSymbol<*>)?.classKind == ClassKind.INTERFACE + && this !is FirPropertyAccessor + } + + private fun FirCallableDeclaration.isNullableProperty() = this is FirProperty && returnTypeRef.coneType.isNullable + + private fun FirDeclaration.hasValidExternalBody(): Boolean { + val body = when (this) { + is FirFunction -> body + is FirAnonymousInitializer -> body + else -> return true + } + + return when { + body is FirSingleExpressionBlock -> body.isDefinedExternallyExpression() + body != null -> { + val statement = body.statements.singleOrNull() ?: return false + statement.isDefinedExternallyExpression() + } + + else -> false + } + } + + private fun FirElement.isDefinedExternallyExpression(): Boolean { + val declaration = (this as? FirPropertyAccessExpression) + ?.calleeReference?.toResolvedPropertySymbol() ?: return false + return declaration.callableId in JsStandardClassIds.Callables.definedExternallyPropertyNames + } +} \ No newline at end of file diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt index 1f6c28e9f15..ebbfb14241e 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt @@ -206,6 +206,11 @@ fun FirNamedFunctionSymbol.overriddenFunctions( return overriddenFunctions } +fun FirClass.collectSupertypesWithDelegates(): Map { + val fieldsMap = delegateFieldsMap ?: emptyMap() + return superTypeRefs.mapIndexed { index, it -> it to fieldsMap[index] }.toMap() +} + /** * Returns the modality of the class */ diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt index 046299c2a25..d020505ae08 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt @@ -1120,7 +1120,7 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte source = parameterSource?.fakeElement(KtFakeSourceElementKind.DataClassGeneratedMembers) moduleData = baseModuleData origin = FirDeclarationOrigin.Source - returnTypeRef = firProperty.returnTypeRef + returnTypeRef = firProperty.returnTypeRef.copyWithNewSourceKind(KtFakeSourceElementKind.DataClassGeneratedMembers) this.name = name status = FirDeclarationStatusImpl(Visibilities.Public, Modality.FINAL).apply { isOperator = true diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt index fe1b19daf23..69ebd386f84 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt @@ -443,13 +443,13 @@ open class FirDeclarationsResolveTransformer(transformer: FirAbstractBodyResolve when { isGetter -> { if (returnTypeRef is FirImplicitTypeRef || forceUpdateForNonImplicitTypes) { - replaceReturnTypeRef(propertyTypeRef) + replaceReturnTypeRef(propertyTypeRef.copyWithNewSource(returnTypeRef.source)) } } isSetter -> { val valueParameter = valueParameters.firstOrNull() ?: return if (valueParameter.returnTypeRef is FirImplicitTypeRef) { - valueParameter.replaceReturnTypeRef(propertyTypeRef) + valueParameter.replaceReturnTypeRef(propertyTypeRef.copyWithNewSource(returnTypeRef.source)) } } } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/Utils.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/Utils.kt index bacd7193f44..f52bfe2c21e 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/Utils.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/Utils.kt @@ -6,12 +6,9 @@ package org.jetbrains.kotlin.fir import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.KtFakeSourceElementKind -import org.jetbrains.kotlin.KtPsiSourceElement -import org.jetbrains.kotlin.KtRealPsiSourceElement +import org.jetbrains.kotlin.* import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Visibility -import org.jetbrains.kotlin.fakeElement import org.jetbrains.kotlin.fir.declarations.FirContextReceiver import org.jetbrains.kotlin.fir.declarations.FirDeclarationStatus import org.jetbrains.kotlin.fir.declarations.FirFile @@ -32,11 +29,15 @@ import org.jetbrains.kotlin.util.wrapIntoSourceCodeAnalysisExceptionIfNeeded // TODO: rewrite fun FirBlock.returnExpressions(): List = listOfNotNull(statements.lastOrNull() as? FirExpression) -// do we need a deep copy here ? fun R.copyWithNewSourceKind(newKind: KtFakeSourceElementKind): R { if (source == null) return this if (source?.kind == newKind) return this - val newSource = source?.fakeElement(newKind) + return copyWithNewSource(source?.fakeElement(newKind)) +} + +// do we need a deep copy here ? +fun R.copyWithNewSource(newSource: KtSourceElement?): R { + if (source?.kind == newSource?.kind) return this @Suppress("UNCHECKED_CAST") return when (val typeRef = this) { @@ -63,7 +64,7 @@ fun R.copyWithNewSourceKind(newKind: KtFakeSourceElementKind): isMarkedNullable = typeRef.isMarkedNullable annotations += typeRef.annotations } - is FirImplicitBuiltinTypeRef -> typeRef.withFakeSource(newKind) + is FirImplicitBuiltinTypeRef -> typeRef.withNewSource(newSource) is FirIntersectionTypeRef -> buildIntersectionTypeRef { source = newSource isMarkedNullable = typeRef.isMarkedNullable diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/utils/FirDeclarationUtil.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/utils/FirDeclarationUtil.kt index 62b298548d2..daad3d7d67b 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/utils/FirDeclarationUtil.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/utils/FirDeclarationUtil.kt @@ -43,3 +43,5 @@ val FirDeclaration.isNonLocal is FirClassLikeDeclaration -> !symbol.classId.isLocal else -> false } + +val FirCallableDeclaration.isExtension get() = receiverParameter != null diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirImplicitBuiltinTypeRef.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirImplicitBuiltinTypeRef.kt index 6f891210291..ef5c2c3b3bc 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirImplicitBuiltinTypeRef.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/impl/FirImplicitBuiltinTypeRef.kt @@ -183,10 +183,9 @@ class FirImplicitKMutableProperty2TypeRef( arrayOf(dispatchReceiverTypeArgument, extensionReceiverTypeArgument, propertyTypeArgument) ) -fun FirImplicitBuiltinTypeRef.withFakeSource(kind: KtFakeSourceElementKind): FirImplicitBuiltinTypeRef { +fun FirImplicitBuiltinTypeRef.withNewSource(newSource: KtSourceElement?): FirImplicitBuiltinTypeRef { val source = source ?: return this - if (source.kind == kind) return this - val newSource = source.fakeElement(kind) + if (source.kind == newSource?.kind) return this return when (this) { is FirImplicitUnitTypeRef -> FirImplicitUnitTypeRef(newSource) is FirImplicitAnyTypeRef -> FirImplicitAnyTypeRef(newSource) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/anonymousInitializer.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/anonymousInitializer.fir.kt deleted file mode 100644 index 2503538c05a..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/anonymousInitializer.fir.kt +++ /dev/null @@ -1,5 +0,0 @@ -external class A { - init { - definedExternally - } -} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/anonymousInitializer.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/anonymousInitializer.kt index a278c387a48..abe4e567248 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/anonymousInitializer.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/anonymousInitializer.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL external class A { init { definedExternally diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/body.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/body.fir.kt deleted file mode 100644 index 8d6a11c7517..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/body.fir.kt +++ /dev/null @@ -1,30 +0,0 @@ -external fun foo(): Int = definedExternally - -external fun bar(): Unit { - definedExternally -} - -external fun baz(): Int = 23 - -external fun f(x: Int, y: String = definedExternally): Unit - -external fun g(x: Int, y: String = ""): Unit - -external var a: Int - get() = definedExternally - set(value) { - definedExternally - } - -external val b: Int - get() = 23 - -external val c: Int = definedExternally - -external val d: Int = 23 - -external class C { - fun foo(): Int = definedExternally - - fun bar(): Int = 23 -} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/body.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/body.kt index 2c1d5a05c32..e4e17042967 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/body.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/body.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL external fun foo(): Int = definedExternally external fun bar(): Unit { @@ -27,4 +28,4 @@ external class C { fun foo(): Int = definedExternally fun bar(): Int = 23 -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/delegatedConstructorCall.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/delegatedConstructorCall.fir.kt index 9c0f69efcee..4893d0ac423 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/delegatedConstructorCall.fir.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/delegatedConstructorCall.fir.kt @@ -1,17 +1,17 @@ // !DIAGNOSTICS: -DEBUG_INFO_MISSING_UNRESOLVED external open class Base(x: Int) { - constructor(x: String) : this(23) + constructor(x: String) : this(23) - constructor(x: String, y: String) : this("") + constructor(x: String, y: String) : this("") } -external open class Derived1() : Base(23) { - constructor(x: Byte) : super(23) +external open class Derived1() : Base(23) { + constructor(x: Byte) : super(23) - constructor(x: String) : super("") + constructor(x: String) : super("") - constructor(x: String, y: String) : super("") + constructor(x: String, y: String) : super("") } -external open class Derived2() : Base("") +external open class Derived2() : Base("") diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/delegation.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/delegation.fir.kt index a41f6194a67..5ef6d8661b9 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/delegation.fir.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/delegation.fir.kt @@ -9,10 +9,10 @@ class Delegate { operator fun setValue(thisRef: Any?, property: Any, value: String) {} } -external class A : I by O { - val prop by Delegate() +external class A : I by O { + val prop by Delegate() - var mutableProp by Delegate() + var mutableProp by Delegate() } -external val topLevelProp by Delegate() +external val topLevelProp by Delegate() diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/enumEntry.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/enumEntry.fir.kt index 9a17d365032..7e7d303c4a9 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/enumEntry.fir.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/enumEntry.fir.kt @@ -1,7 +1,7 @@ external enum class E { X, - Y { + Y { fun foo() - }, - Z {} + }, + Z {} } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.fir.kt deleted file mode 100644 index 3cdf8023cc8..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.fir.kt +++ /dev/null @@ -1,10 +0,0 @@ -class A - -external fun A.foo(): Unit = definedExternally - -external var A.bar: String - get() = definedExternally - set(value) = definedExternally - -external val A.baz: String - get() = definedExternally diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.kt index 65cef38a05e..868dbfa26b0 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL class A external fun A.foo(): Unit = definedExternally diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionArgumentOrReturnType.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionArgumentOrReturnType.fir.kt deleted file mode 100644 index 4be70a6344b..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionArgumentOrReturnType.fir.kt +++ /dev/null @@ -1,25 +0,0 @@ -external fun foo(f: Int.() -> Int) - -external fun bar(vararg f: Int.() -> Int) - -external fun baz(): Int.() -> Int - -external val prop: Int.() -> Int - -external var prop2: Int.() -> Int - -external val propGet - get(): Int.() -> Int = definedExternally - -external var propSet - get(): Int.() -> Int = definedExternally - set(v: Int.() -> Int) = definedExternally - -external class A(f: Int.() -> Int) - -external data class B( - val a: Int.() -> Int, - var b: Int.() -> Int -) { - val c: Int.() -> Int -} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionArgumentOrReturnType.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionArgumentOrReturnType.kt index dfe629c5eeb..2bd7f766216 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionArgumentOrReturnType.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionArgumentOrReturnType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL external fun foo(f: Int.() -> Int) external fun bar(vararg f: Int.() -> Int) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/externalFunInterface.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/externalFunInterface.fir.kt deleted file mode 100644 index 2eba53f9de8..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/externalFunInterface.fir.kt +++ /dev/null @@ -1,3 +0,0 @@ -external fun interface I { - fun f() -} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/externalFunInterface.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/externalFunInterface.kt index 416e9f50ce8..bc9ff0c987a 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/externalFunInterface.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/externalFunInterface.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL external fun interface I { fun f() } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/externalInterfaceNested.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/externalInterfaceNested.fir.kt deleted file mode 100644 index fd07443247b..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/externalInterfaceNested.fir.kt +++ /dev/null @@ -1,11 +0,0 @@ -external interface I { - interface J - - class C - - object O - - enum class E - - companion object -} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/externalInterfaceNested.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/externalInterfaceNested.kt index a8121993f53..2abebfa2b03 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/externalInterfaceNested.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/externalInterfaceNested.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL external interface I { interface J diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/inheritance.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/inheritance.fir.kt deleted file mode 100644 index 3593fd79261..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/inheritance.fir.kt +++ /dev/null @@ -1,19 +0,0 @@ -open class A - -interface I - -external open class B - -external class C : A - -external class D : B, I - -external interface K : I - -external enum class E { - X -} - -external enum class F : I { - X -} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/inheritance.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/inheritance.kt index 005a78cc4e9..443451008bf 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/inheritance.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/inheritance.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL open class A interface I diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/inline.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/inline.fir.kt deleted file mode 100644 index 99fc7706c87..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/inline.fir.kt +++ /dev/null @@ -1,19 +0,0 @@ -// !DIAGNOSTICS: -NOTHING_TO_INLINE - -inline external fun foo(): Unit - -inline external val bar: Int - get() = definedExternally - -external val baz: Int - inline get() = definedExternally - -external class A { - inline fun foo(): Unit - - inline val bar: Int - get() = definedExternally - - val baz: Int - inline get() = definedExternally -} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/inline.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/inline.kt index 086db897375..25dd0e08d42 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/inline.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/inline.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -NOTHING_TO_INLINE inline external fun foo(): Unit diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClass.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClass.fir.kt deleted file mode 100644 index 9ce0b240caa..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClass.fir.kt +++ /dev/null @@ -1,9 +0,0 @@ -// !LANGUAGE: +InlineClasses, -JvmInlineValueClasses - -external inline class C(val a: Int) { - fun foo() -} - -inline external enum class E { - A -} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClass.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClass.kt index 7c5f9b25cbf..488cadab30b 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClass.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClass.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +InlineClasses, -JvmInlineValueClasses external inline class C(val a: Int) { diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType.kt.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType.kt.fir.kt deleted file mode 100644 index 065455f3f00..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType.kt.fir.kt +++ /dev/null @@ -1,64 +0,0 @@ -// !LANGUAGE: +InlineClasses, -JvmInlineValueClasses - -// FILE: uint.kt - -package kotlin - -inline class UInt(private val i: Int) - -// FILE: test.kt - -inline class SomeIC(val a: Int) - -external val l: SomeIC - -external val ll - get(): SomeIC = definedExternally - -external var r: SomeIC - -external var rr: SomeIC - get() = definedExternally - set(v: SomeIC) { definedExternally } - -external fun foo(): SomeIC -external fun foo(c: SomeIC): SomeIC -external fun foo(a: Int, c: SomeIC): SomeIC - -external fun foo(a: Int, vararg args: SomeIC) -external fun foo(a: Int, ui: UInt, vararg args: UInt) - -external class CC( - a: SomeIC, - val b: SomeIC, - var c: SomeIC -) { - val l: SomeIC - var r: SomeIC - - fun foo(): SomeIC - fun foo(c: SomeIC): SomeIC - fun foo(a: Int, c: SomeIC): SomeIC - - class N( - a: SomeIC, - val b: SomeIC, - var c: SomeIC - ) { - val l: SomeIC - var r: SomeIC - - fun foo(): SomeIC - fun foo(c: SomeIC): SomeIC - fun foo(a: Int, c: SomeIC): SomeIC - } -} - -external interface EI { - val l: SomeIC - var r: SomeIC - - fun foo(): SomeIC - fun foo(c: SomeIC): SomeIC - fun foo(a: Int, c: SomeIC): SomeIC -} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType.kt.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType.kt.kt index b3ae0119402..1ce3eb7cb2c 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType.kt.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType.kt.kt @@ -1,4 +1,5 @@ -// !LANGUAGE: +InlineClasses, -JvmInlineValueClasses +// FIR_IDENTICAL +// !LANGUAGE: +InlineClasses, -JvmInlineValueClasses, -JsAllowValueClassesInExternals // FILE: uint.kt diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType_allowed.kt.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType_allowed.kt.fir.kt deleted file mode 100644 index 34864047ded..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType_allowed.kt.fir.kt +++ /dev/null @@ -1,65 +0,0 @@ -// !LANGUAGE: +InlineClasses, -JvmInlineValueClasses, +JsAllowValueClassesInExternals -// !DIAGNOSTICS: +INLINE_CLASS_IN_EXTERNAL_DECLARATION_WARNING - -// FILE: uint.kt - -package kotlin - -inline class UInt(private val i: Int) - -// FILE: test.kt - -inline class SomeIC(val a: Int) - -external val l: SomeIC - -external val ll - get(): SomeIC = definedExternally - -external var r: SomeIC - -external var rr: SomeIC - get() = definedExternally - set(v: SomeIC) { definedExternally } - -external fun foo(): SomeIC -external fun foo(c: SomeIC): SomeIC -external fun foo(a: Int, c: SomeIC): SomeIC - -external fun foo(a: Int, vararg args: SomeIC) -external fun foo(a: Int, ui: UInt, vararg args: UInt) - -external class CC( - a: SomeIC, - val b: SomeIC, - var c: SomeIC -) { - val l: SomeIC - var r: SomeIC - - fun foo(): SomeIC - fun foo(c: SomeIC): SomeIC - fun foo(a: Int, c: SomeIC): SomeIC - - class N( - a: SomeIC, - val b: SomeIC, - var c: SomeIC - ) { - val l: SomeIC - var r: SomeIC - - fun foo(): SomeIC - fun foo(c: SomeIC): SomeIC - fun foo(a: Int, c: SomeIC): SomeIC - } -} - -external interface EI { - val l: SomeIC - var r: SomeIC - - fun foo(): SomeIC - fun foo(c: SomeIC): SomeIC - fun foo(a: Int, c: SomeIC): SomeIC -} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType_allowed.kt.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType_allowed.kt.kt index 9425032d850..4650d8173eb 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType_allowed.kt.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType_allowed.kt.kt @@ -1,4 +1,6 @@ +// FIR_IDENTICAL // !LANGUAGE: +InlineClasses, -JvmInlineValueClasses, +JsAllowValueClassesInExternals +// !DIAGNOSTICS: +INLINE_CLASS_IN_EXTERNAL_DECLARATION_WARNING // FILE: uint.kt diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/innerClass.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/innerClass.fir.kt deleted file mode 100644 index dffb71cb484..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/innerClass.fir.kt +++ /dev/null @@ -1,9 +0,0 @@ -external class C { - inner class Inner -} - -external enum class E { - X; - - inner class Inner -} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/innerClass.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/innerClass.kt index 021c3a2fe82..217f16fe095 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/innerClass.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/innerClass.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL external class C { inner class Inner } @@ -6,4 +7,4 @@ external enum class E { X; inner class Inner -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.fir.kt deleted file mode 100644 index 1e5d8192432..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.fir.kt +++ /dev/null @@ -1,41 +0,0 @@ -object O - -class TopLevel { - external class A - - class B - - fun foo() = 23 - - external fun bar(): Int - - val x = "a" - - external val y: String - - val O.u: String get() = "O.u" -} - -external class TopLevelNative { - external class A - - class B - - fun foo(): Int = definedExternally - - external fun bar(): Int - - val x: String = definedExternally - - external val y: String -} - -fun topLevelFun() { - external class A - - class B - - fun foo() = 23 - - external fun bar(): Int -} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.kt index 459d8e12857..4c8a16fb56c 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL object O class TopLevel { @@ -39,4 +40,3 @@ fun topLevelFun() { external fun bar(): Int } - diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nonAbstractMembersOfInterface.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nonAbstractMembersOfInterface.fir.kt deleted file mode 100644 index 147e87e1dd4..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nonAbstractMembersOfInterface.fir.kt +++ /dev/null @@ -1,21 +0,0 @@ -external interface I { - fun foo(): Unit = definedExternally - - val a: Int? - get() = definedExternally - - var b: String? - get() = definedExternally - set(value) = definedExternally - - val c: Int - get() = definedExternally - - var d: String - get() = definedExternally - set(value) = definedExternally - - var e: dynamic - get() = definedExternally - set(value) = definedExternally -} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nonAbstractMembersOfInterface.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nonAbstractMembersOfInterface.kt index 8bd27bc3891..5e950953b1f 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nonAbstractMembersOfInterface.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nonAbstractMembersOfInterface.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL external interface I { fun foo(): Unit = definedExternally diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/privateMembers.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/privateMembers.fir.kt deleted file mode 100644 index d1547a2f9b3..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/privateMembers.fir.kt +++ /dev/null @@ -1,68 +0,0 @@ -// !DIAGNOSTICS: -NOTHING_TO_INLINE -// TODO: should we disable NOTHING_TO_INLINE in JS backend? -// TODO: uncomment declarations in case we decide to implement KT-14031 - -external class C { - private fun a(): Int - - private val b: String - - private var c: Float - - private var d: Float - get - set - - var e: Float - get - private set - - /* - private inline fun inline_a(): Int = 23 - - private inline val inline_prop: Int - get() = 42 - */ -} - -external object O { - private fun a(): Int - - private val b: String - - private var c: Float - - private var d: Float - get - set - - /* - private inline fun inline_a(): Int = 23 - - private inline val inline_prop: Int - get() = 42 - */ -} - -external class Outer { - class Inner { - private fun a(): Int - - private val b: String - - private var c: Float - - private var d: Float - get - set - - /* - private inline fun inline_a(): Int = 23 - - private inline val inline_prop: Int - get() = 42 - */ - } - - private class PrivateInner -} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/privateMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/privateMembers.kt index 9bef2e9dada..59c8039503b 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/privateMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/privateMembers.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -NOTHING_TO_INLINE // TODO: should we disable NOTHING_TO_INLINE in JS backend? // TODO: uncomment declarations in case we decide to implement KT-14031 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/propertyParameter.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/propertyParameter.fir.kt deleted file mode 100644 index 89f2958f218..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/propertyParameter.fir.kt +++ /dev/null @@ -1 +0,0 @@ -external class C(x: Int, val y: String) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/propertyParameter.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/propertyParameter.kt index 4034589e7b7..70ef9b6a9ac 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/propertyParameter.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/propertyParameter.kt @@ -1 +1,2 @@ +// FIR_IDENTICAL external class C(x: Int, val y: String) \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.fir.kt deleted file mode 100644 index f4fbf510832..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.fir.kt +++ /dev/null @@ -1,21 +0,0 @@ -external annotation class A(val x: Int) - -val x: Int - external get() = definedExternally - -class B - -val B.x: Int - external get() = definedExternally - -class C { - val a: Int - external get() = definedExternally -} - -external class D { - val a: Int - external get() = definedExternally -} - -external data class E(val x: Int) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.kt index a2d46a963aa..19d260c539e 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL external annotation class A(val x: Int) val x: Int diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsExternalChecker.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsExternalChecker.kt index 3a8a1181521..12e591689ec 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsExternalChecker.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsExternalChecker.kt @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticSink import org.jetbrains.kotlin.js.PredefinedAnnotation import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils import org.jetbrains.kotlin.lexer.KtTokens -import org.jetbrains.kotlin.name.FqNameUnsafe +import org.jetbrains.kotlin.name.JsStandardClassIds import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DescriptorUtils @@ -28,7 +28,8 @@ import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils object JsExternalChecker : DeclarationChecker { - val DEFINED_EXTERNALLY_PROPERTY_NAMES = setOf(FqNameUnsafe("kotlin.js.noImpl"), FqNameUnsafe("kotlin.js.definedExternally")) + val DEFINED_EXTERNALLY_PROPERTY_NAMES = JsStandardClassIds.Callables.definedExternallyPropertyNames + .map { it.asSingleFqName().toUnsafe() } override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) { if (!AnnotationsUtils.isNativeObject(descriptor)) return diff --git a/js/js.translator/testData/box/native/passExtLambdaToNative.kt b/js/js.translator/testData/box/native/passExtLambdaToNative.kt index a6cd9dfc0d1..88fbb752bef 100644 --- a/js/js.translator/testData/box/native/passExtLambdaToNative.kt +++ b/js/js.translator/testData/box/native/passExtLambdaToNative.kt @@ -1,4 +1,5 @@ // IGNORE_BACKEND_K1: JS_IR +// IGNORE_BACKEND_K2: JS_IR // IGNORE_BACKEND: JS_IR_ES6 // TODO: Unmute when extension functions are supported in external declarations. // IGNORE_BACKEND: JS diff --git a/js/js.translator/testData/box/native/passMemberOrExtToNative.kt b/js/js.translator/testData/box/native/passMemberOrExtToNative.kt index 409d72e01ad..1160e056f1a 100644 --- a/js/js.translator/testData/box/native/passMemberOrExtToNative.kt +++ b/js/js.translator/testData/box/native/passMemberOrExtToNative.kt @@ -1,4 +1,5 @@ // IGNORE_BACKEND_K1: JS_IR +// IGNORE_BACKEND_K2: JS_IR // IGNORE_BACKEND: JS_IR_ES6 // TODO: Unmute when extension functions are supported in external declarations. // IGNORE_BACKEND: JS