From f62ffeaa0ae46a5c9df248d6ef18ded75840026d Mon Sep 17 00:00:00 2001 From: Sergej Jaskiewicz Date: Mon, 6 Sep 2021 13:08:08 +0300 Subject: [PATCH] [JS, Frontend] Forbid `@JsExport`ing inline/value classes Previously the compiler would just crash. #KT-46202 Fixed --- .../export/wrongExportedDeclaration.kt | 13 ++++++++ .../export/wrongExportedDeclaration.txt | 32 +++++++++++++++++++ .../diagnostics/JsExportDeclarationChecker.kt | 4 +++ 3 files changed, 49 insertions(+) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/export/wrongExportedDeclaration.kt b/compiler/testData/diagnostics/testsWithJsStdLib/export/wrongExportedDeclaration.kt index bc84713c50e..a9d85b0d982 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/export/wrongExportedDeclaration.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/export/wrongExportedDeclaration.kt @@ -1,5 +1,6 @@ // !USE_EXPERIMENTAL: kotlin.js.ExperimentalJsExport // !RENDER_DIAGNOSTICS_MESSAGES +// !DIAGNOSTICS: -INLINE_CLASS_DEPRECATED package foo @@ -24,3 +25,15 @@ interface SomeInterface @JsExport external interface GoodInterface + +@JsExport +value class A(val a: Int) + +@JsExport +inline class B(val b: Int) + +@JsExport +inline value class C(val c: Int) + +@JsExport +value inline class D(val d: Int) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/export/wrongExportedDeclaration.txt b/compiler/testData/diagnostics/testsWithJsStdLib/export/wrongExportedDeclaration.txt index f45ea89aa8f..dffbdd42be7 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/export/wrongExportedDeclaration.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/export/wrongExportedDeclaration.txt @@ -5,6 +5,14 @@ package foo { @kotlin.js.JsExport public inline fun inlineReifiedFun(/*0*/ x: kotlin.Any): kotlin.Boolean @kotlin.js.JsExport public suspend fun suspendFun(): kotlin.Unit + @kotlin.js.JsExport public final value class A { + public constructor A(/*0*/ a: kotlin.Int) + public final val a: kotlin.Int + public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String + } + @kotlin.js.JsExport public final annotation class AnnotationClass : kotlin.Annotation { public constructor AnnotationClass() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean @@ -12,6 +20,30 @@ package foo { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } + @kotlin.js.JsExport public final inline class B { + public constructor B(/*0*/ b: kotlin.Int) + public final val b: kotlin.Int + public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String + } + + @kotlin.js.JsExport public final inline value class C { + public constructor C(/*0*/ c: kotlin.Int) + public final val c: kotlin.Int + public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String + } + + @kotlin.js.JsExport public final inline value class D { + public constructor D(/*0*/ d: kotlin.Int) + public final val d: kotlin.Int + public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String + } + @kotlin.js.JsExport public final enum class EnumClass : kotlin.Enum { enum entry ENTRY1 diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsExportDeclarationChecker.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsExportDeclarationChecker.kt index f45bf578910..69875c1d021 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsExportDeclarationChecker.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsExportDeclarationChecker.kt @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal import org.jetbrains.kotlin.resolve.descriptorUtil.isExtensionProperty import org.jetbrains.kotlin.resolve.inline.isInlineWithReified +import org.jetbrains.kotlin.resolve.isInlineClass import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.isDynamic import org.jetbrains.kotlin.types.typeUtil.* @@ -111,6 +112,9 @@ object JsExportDeclarationChecker : DeclarationChecker { ENUM_CLASS -> "enum class" INTERFACE -> if (descriptor.isExternal) null else "interface" ANNOTATION_CLASS -> "annotation class" + CLASS -> if (descriptor.isInlineClass()) { + "${if (descriptor.isInline) "inline " else ""}${if (descriptor.isValue) "value " else ""}class" + } else null else -> null }