[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>() class <!NON_EXPORTABLE_TYPE("super; ExportedGenericClass<NonExportedClass>")!>ExportedClass3<!> : ExportedGenericClass<NonExportedClass>()
@JsExport @JsExport
interface ExportedGenericInterface<T> interface <!WRONG_EXPORTED_DECLARATION!>ExportedGenericInterface<!><T>
@JsExport @JsExport
class <!NON_EXPORTABLE_TYPE("super; ExportedGenericInterface<NonExportedClass>")!>ExportedClass4<!> : ExportedGenericInterface<NonExportedClass> 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<!>> class A<<!NON_EXPORTABLE_TYPE("upper bound; C")!>T : C<!>, <!NON_EXPORTABLE_TYPE("upper bound; I")!>S: I<!>>
@JsExport @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 @JsExport
annotation class <!WRONG_EXPORTED_DECLARATION("annotation class")!>AnnotationClass<!> 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 valueOf(/*0*/ value: kotlin.String): foo.EnumClass
public final /*synthesized*/ fun values(): kotlin.Array<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) checkTypeParameter(typeParameter)
} }
if (descriptor.kind == ENUM_CLASS) { val wrongDeclaration: String? = when (descriptor.kind) {
reportWrongExportedDeclaration("enum class") ENUM_CLASS -> "enum class"
return INTERFACE -> if (descriptor.isExternal) null else "interface"
} ANNOTATION_CLASS -> "annotation class"
if (descriptor.kind == ANNOTATION_CLASS) { else -> null
reportWrongExportedDeclaration("annotation class") }
if (wrongDeclaration != null) {
reportWrongExportedDeclaration(wrongDeclaration)
return return
} }
if (descriptor.kind == ENUM_ENTRY) { if (descriptor.kind == ENUM_ENTRY) {
// Covered by ENUM_CLASS // Covered by ENUM_CLASS
return return
@@ -1,6 +1,5 @@
// EXPECTED_REACHABLE_NODES: 1282 // EXPECTED_REACHABLE_NODES: 1282
@JsExport
interface I { interface I {
fun ok(): String fun ok(): String
} }