[JS] Forbid export of interfaces

With the only exception of external interfaces.

See https://youtrack.jetbrains.com/issue/KT-44099
This commit is contained in:
Shagen Ogandzhanian
2020-12-29 20:43:57 +01:00
parent a6534c4653
commit 55a5695fc0
6 changed files with 30 additions and 9 deletions
@@ -20,7 +20,7 @@ open class ExportedGenericClass<T>
class <!NON_EXPORTABLE_TYPE("super; ExportedGenericClass<NonExportedClass>")!>ExportedClass3<!> : ExportedGenericClass<NonExportedClass>()
@JsExport
interface ExportedGenericInterface<T>
interface <!WRONG_EXPORTED_DECLARATION!>ExportedGenericInterface<!><T>
@JsExport
class <!NON_EXPORTABLE_TYPE("super; ExportedGenericInterface<NonExportedClass>")!>ExportedClass4<!> : ExportedGenericInterface<NonExportedClass>
@@ -14,4 +14,4 @@ fun <<!NON_EXPORTABLE_TYPE("upper bound; C")!>T : C<!>>foo() { }
class A<<!NON_EXPORTABLE_TYPE("upper bound; C")!>T : C<!>, <!NON_EXPORTABLE_TYPE("upper bound; I")!>S: I<!>>
@JsExport
interface I2<<!NON_EXPORTABLE_TYPE("upper bound; C"), NON_EXPORTABLE_TYPE("upper bound; I")!>T<!>> where T : C, T : I
interface <!WRONG_EXPORTED_DECLARATION!>I2<!><<!NON_EXPORTABLE_TYPE("upper bound; C"), NON_EXPORTABLE_TYPE("upper bound; I")!>T<!>> where T : C, T : I
@@ -18,3 +18,9 @@ enum class <!WRONG_EXPORTED_DECLARATION("enum class")!>EnumClass<!> { ENTRY1, EN
@JsExport
annotation class <!WRONG_EXPORTED_DECLARATION("annotation class")!>AnnotationClass<!>
@JsExport
interface <!WRONG_EXPORTED_DECLARATION("interface")!>SomeInterface<!>
@JsExport
external interface GoodInterface
@@ -30,4 +30,16 @@ package foo {
public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): foo.EnumClass
public final /*synthesized*/ fun values(): kotlin.Array<foo.EnumClass>
}
@kotlin.js.JsExport public external interface GoodInterface {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@kotlin.js.JsExport public interface SomeInterface {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
@@ -107,14 +107,18 @@ object JsExportDeclarationChecker : DeclarationChecker {
checkTypeParameter(typeParameter)
}
if (descriptor.kind == ENUM_CLASS) {
reportWrongExportedDeclaration("enum class")
return
}
if (descriptor.kind == ANNOTATION_CLASS) {
reportWrongExportedDeclaration("annotation class")
val wrongDeclaration: String? = when (descriptor.kind) {
ENUM_CLASS -> "enum class"
INTERFACE -> if (descriptor.isExternal) null else "interface"
ANNOTATION_CLASS -> "annotation class"
else -> null
}
if (wrongDeclaration != null) {
reportWrongExportedDeclaration(wrongDeclaration)
return
}
if (descriptor.kind == ENUM_ENTRY) {
// Covered by ENUM_CLASS
return
@@ -1,6 +1,5 @@
// EXPECTED_REACHABLE_NODES: 1282
@JsExport
interface I {
fun ok(): String
}