From d0ffb5bd3208b47776167739c2e9c63bc3ea41e3 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Fri, 25 Nov 2016 17:52:40 +0300 Subject: [PATCH] JS: add restrictions to `external` modifier according to KT-13893 --- .../nativeGetter/onLocalNativeClassMembers.kt | 45 ------------- .../onLocalNativeClassMembers.txt | 3 - .../nativeInvoke/onLocalNativeClassMembers.kt | 25 ------- .../onLocalNativeClassMembers.txt | 3 - .../nativeSetter/onLocalNativeClassMembers.kt | 60 ----------------- .../onLocalNativeClassMembers.txt | 3 - .../testsWithJsStdLib/native/nested.kt | 51 +++++++++++++++ .../testsWithJsStdLib/native/nested.txt | 65 +++++++++++++++++++ .../nested/nativeInnerClassProhibited.kt | 7 -- .../nested/nativeInnerClassProhibited.txt | 29 --------- .../native/optionlBody/native.kt | 9 --- .../native/optionlBody/native.txt | 1 - .../testsWithJsStdLib/native/wrongTarget.kt | 19 ++++++ .../testsWithJsStdLib/native/wrongTarget.txt | 34 ++++++++++ .../DiagnosticsTestWithJsStdLibGenerated.java | 45 ++++--------- .../js/resolve/JsPlatformConfigurator.kt | 5 +- .../diagnostics/DefaultErrorMessagesJs.kt | 2 +- .../js/resolve/diagnostics/ErrorsJs.java | 2 +- .../resolve/diagnostics/JsExternalChecker.kt | 57 ++++++++++++++++ .../diagnostics/NativeInnerClassChecker.kt | 37 ----------- js/js.libraries/src/builtins/hacks.kt | 2 +- js/js.libraries/src/core/annotations.kt | 14 ++-- js/js.libraries/src/core/concurrent.kt | 4 +- js/js.libraries/src/junit/core.kt | 2 +- .../box/expression/function/mangling.kt | 60 ++++++++++++----- .../testData/box/native/classObject.kt | 4 +- 26 files changed, 298 insertions(+), 290 deletions(-) delete mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNativeClassMembers.kt delete mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNativeClassMembers.txt delete mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalNativeClassMembers.kt delete mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalNativeClassMembers.txt delete mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNativeClassMembers.kt delete mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNativeClassMembers.txt create mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/native/nested.kt create mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/native/nested.txt delete mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/native/nested/nativeInnerClassProhibited.kt delete mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/native/nested/nativeInnerClassProhibited.txt create mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.kt create mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.txt create mode 100644 js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsExternalChecker.kt delete mode 100644 js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/NativeInnerClassChecker.kt diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNativeClassMembers.kt deleted file mode 100644 index 6b758314673..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNativeClassMembers.kt +++ /dev/null @@ -1,45 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -fun foo() { - external class A { - @nativeGetter - fun get(a: String): Any? = null - - @nativeGetter - fun take(a: Number): String? = null - - @nativeGetter - fun foo(a: Double): String? = null - } - - external class B { - @nativeGetter - val foo = 0 - } - - external class C { - @nativeGetter - fun Int.get(a: String): Int? = 1 - - @nativeGetter - fun Int.get2(a: Number): String? = "OK" - - @nativeGetter - fun Int.get3(a: Int): String? = "OK" - - @nativeGetter - fun get(): Any? = null - - @nativeGetter - fun get(a: A): Any? = null - - @nativeGetter - fun foo(a: Int) {} - - @nativeGetter - fun bar(a: String): Int = 0 - - @nativeGetter - fun baz(a: String = "foo"): Int? = 0 - } -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNativeClassMembers.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNativeClassMembers.txt deleted file mode 100644 index 65a6ac47e1f..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNativeClassMembers.txt +++ /dev/null @@ -1,3 +0,0 @@ -package - -public fun foo(): kotlin.Unit diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalNativeClassMembers.kt deleted file mode 100644 index d9534b70af4..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalNativeClassMembers.kt +++ /dev/null @@ -1,25 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -fun foo() { - external class A { - @nativeInvoke - fun foo() {} - - @nativeInvoke - fun invoke(a: String): Int = 0 - - @nativeInvoke - fun Int.ext() = 1 - - @nativeInvoke - fun Int.invoke(a: String, b: Int) = "OK" - - val anonymous = object { - @nativeInvoke - fun foo() {} - - @nativeInvoke - fun invoke(a: String): Int = 0 - } - } -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalNativeClassMembers.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalNativeClassMembers.txt deleted file mode 100644 index 65a6ac47e1f..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalNativeClassMembers.txt +++ /dev/null @@ -1,3 +0,0 @@ -package - -public fun foo(): kotlin.Unit diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNativeClassMembers.kt deleted file mode 100644 index 682fa55edcf..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNativeClassMembers.kt +++ /dev/null @@ -1,60 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION - -fun foo() { - @native - class A { - @nativeSetter - fun set(a: String, v: Any?): Any? = null - - @nativeSetter - fun put(a: Number, v: String) {} - - @nativeSetter - fun foo(a: Int, v: String) {} - - @nativeSetter - fun set4(a: Double, v: String): Any = 1 - - @nativeSetter - fun set5(a: Double, v: String): CharSequence = "OK" - } - - @native - class B { - @nativeSetter - val foo = 0 - } - - @native - class C { - @nativeSetter - fun Int.set(a: String, v: Int) {} - - @nativeSetter - fun Int.set2(a: Number, v: String?) = "OK" - - @nativeSetter - fun Int.set3(a: Double, v: String?) = "OK" - - @nativeSetter - fun set6(a: Double, v: String): Number = 1 - - @nativeSetter - fun set(): Any? = null - - @nativeSetter - fun set(a: A): Any? = null - - @nativeSetter - fun set(a: String, v: Any, v2: Any) {} - - @nativeSetter - fun set(a: A, v: Any?) {} - - @nativeSetter - fun foo(a: Number = 0.0, v: String) = "OK" - - @nativeSetter - fun boo(a: Number, v: String = "str") = "OK" - } -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNativeClassMembers.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNativeClassMembers.txt deleted file mode 100644 index 65a6ac47e1f..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNativeClassMembers.txt +++ /dev/null @@ -1,3 +0,0 @@ -package - -public fun foo(): kotlin.Unit diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.kt new file mode 100644 index 00000000000..88aa254b561 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.kt @@ -0,0 +1,51 @@ +// !DIAGNOSTICS: -DEPRECATION +object O + +class TopLevel { + external class A + + class B + + fun foo() = 23 + + external fun bar(): Int + + @native fun baz(): Int + + val x = "a" + + external val y: String + + val O.u: String get() = "O.u" + + external val O.v: String get() = noImpl +} + +external class TopLevelNative { + 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 val O.v: String get() = noImpl +} + +fun topLevelFun() { + external class A + + class B + + fun foo() = 23 + + external fun bar(): Int +} + diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.txt new file mode 100644 index 00000000000..f20af61fe57 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.txt @@ -0,0 +1,65 @@ +package + +public fun topLevelFun(): kotlin.Unit + +public object O { + private constructor O() + 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 +} + +public final class TopLevel { + public constructor TopLevel() + public final val x: kotlin.String = "a" + public final val y: kotlin.String + public final val O.u: kotlin.String + public final val O.v: kotlin.String + public final external fun bar(): kotlin.Int + @kotlin.js.native public final fun baz(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public final class A { + public constructor A() + 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 + } + + public final class B { + public constructor B() + 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 + } +} + +public final class TopLevelNative { + public constructor TopLevelNative() + public final val x: kotlin.String = "a" + public final val y: kotlin.String + public final val O.u: kotlin.String + public final val O.v: kotlin.String + public final external fun bar(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public final class A { + public constructor A() + 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 + } + + public final class B { + public constructor B() + 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 + } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested/nativeInnerClassProhibited.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested/nativeInnerClassProhibited.kt deleted file mode 100644 index bb09e44d45e..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested/nativeInnerClassProhibited.kt +++ /dev/null @@ -1,7 +0,0 @@ -class A { - external inner class B -} - -external class C { - inner external class D -} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested/nativeInnerClassProhibited.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested/nativeInnerClassProhibited.txt deleted file mode 100644 index 255c25b2839..00000000000 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested/nativeInnerClassProhibited.txt +++ /dev/null @@ -1,29 +0,0 @@ -package - -public final class A { - public constructor A() - 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 - - public final inner class B { - public constructor B() - 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 - } -} - -public final class C { - public constructor C() - 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 - - public final inner class D { - public constructor D() - 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 - } -} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.kt index 0220c3732f4..eaded577aac 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.kt @@ -51,13 +51,4 @@ external object O { fun bar(s: String): String = noImpl } -fun test() { - external class Local { - val baz: Int - val boo: Int = noImpl - - fun foo() - fun bar() {} - } -} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.txt index 6a4d5db6db6..587f7d2055f 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.txt @@ -5,7 +5,6 @@ public val boo: kotlin.Int public val kotlin.Int.baz: kotlin.Int public external fun bar(): kotlin.Unit public external fun foo(): kotlin.Unit -public fun test(): kotlin.Unit public external fun kotlin.String.bar(): kotlin.Int public external fun kotlin.String.foo(): kotlin.Int diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.kt new file mode 100644 index 00000000000..21306d94020 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.kt @@ -0,0 +1,19 @@ +external annotation class A + +val x: Int + external get() = noImpl + +class B + +val B.x: Int + external get() = noImpl + +class C { + val a: Int + external get() = noImpl +} + +external class D { + val a: Int + external get() = noImpl +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.txt new file mode 100644 index 00000000000..b0ef11f8e9a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.txt @@ -0,0 +1,34 @@ +package + +public val x: kotlin.Int +public val B.x: kotlin.Int + +public final annotation class A : kotlin.Annotation { + public constructor A() + 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 +} + +public final class B { + public constructor B() + 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 +} + +public final class C { + public constructor C() + public final val a: kotlin.Int + 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 +} + +public external final class D { + public constructor D() + public final val a: kotlin.Int + 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 +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java index 6a3e662cf7b..c8462fcc269 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java @@ -515,6 +515,18 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithJsStdLib/native"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("nested.kt") + public void testNested() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/nested.kt"); + doTest(fileName); + } + + @TestMetadata("wrongTarget.kt") + public void testWrongTarget() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.kt"); + doTest(fileName); + } + @TestMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -529,12 +541,6 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes doTest(fileName); } - @TestMetadata("onLocalNativeClassMembers.kt") - public void testOnLocalNativeClassMembers() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNativeClassMembers.kt"); - doTest(fileName); - } - @TestMetadata("onLocalNonNativeClassMembers.kt") public void testOnLocalNonNativeClassMembers() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNonNativeClassMembers.kt"); @@ -598,12 +604,6 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes doTest(fileName); } - @TestMetadata("onLocalNativeClassMembers.kt") - public void testOnLocalNativeClassMembers() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalNativeClassMembers.kt"); - doTest(fileName); - } - @TestMetadata("onLocalNonNativeClassMembers.kt") public void testOnLocalNonNativeClassMembers() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalNonNativeClassMembers.kt"); @@ -667,12 +667,6 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes doTest(fileName); } - @TestMetadata("onLocalNativeClassMembers.kt") - public void testOnLocalNativeClassMembers() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNativeClassMembers.kt"); - doTest(fileName); - } - @TestMetadata("onLocalNonNativeClassMembers.kt") public void testOnLocalNonNativeClassMembers() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNonNativeClassMembers.kt"); @@ -722,21 +716,6 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes } } - @TestMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/nested") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Nested extends AbstractDiagnosticsTestWithJsStdLib { - public void testAllFilesPresentInNested() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithJsStdLib/native/nested"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); - } - - @TestMetadata("nativeInnerClassProhibited.kt") - public void testNativeInnerClassProhibited() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/nested/nativeInnerClassProhibited.kt"); - doTest(fileName); - } - } - @TestMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatformConfigurator.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatformConfigurator.kt index 1a92fdb6bf7..0a8b1a7e1af 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatformConfigurator.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatformConfigurator.kt @@ -33,9 +33,10 @@ import org.jetbrains.kotlin.types.DynamicTypesAllowed object JsPlatformConfigurator : PlatformConfigurator( DynamicTypesAllowed(), additionalDeclarationCheckers = listOf( - NativeInvokeChecker(), NativeGetterChecker(), NativeSetterChecker(), NativeInnerClassChecker(), + NativeInvokeChecker(), NativeGetterChecker(), NativeSetterChecker(), JsNameChecker, JsModuleChecker, - PlatformImplDeclarationChecker() + PlatformImplDeclarationChecker(), + JsExternalChecker() ), additionalCallCheckers = listOf(ReifiedTypeParameterSubstitutionChecker(), JsModuleCallChecker), additionalTypeCheckers = listOf(), diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/DefaultErrorMessagesJs.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/DefaultErrorMessagesJs.kt index 89e0c3d4ee6..6ab90cf1999 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/DefaultErrorMessagesJs.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/DefaultErrorMessagesJs.kt @@ -37,7 +37,7 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy { put(ErrorsJs.NOT_SUPPORTED, "Cannot translate (not supported yet): ''{0}''", RenderFirstLineOfElementText) put(ErrorsJs.REFERENCE_TO_BUILTIN_MEMBERS_NOT_SUPPORTED, "Callable references for builtin members are not supported yet: ''{0}''", RenderFirstLineOfElementText) put(ErrorsJs.JSCODE_NO_JAVASCRIPT_PRODUCED, "Argument must be non-empty JavaScript code") - put(ErrorsJs.NATIVE_INNER_CLASS_PROHIBITED, "Native inner classes are prohibited") + put(ErrorsJs.NESTED_EXTERNAL_DECLARATION, "Non top-level `external` declaration") put(ErrorsJs.JS_NAME_CLASH, "JavaScript name ({0}) generated for this declaration clashes with another declaration: {1}", Renderers.STRING, Renderers.COMPACT) put(ErrorsJs.JS_FAKE_NAME_CLASH, "JavaScript name {0} is generated for different inherited members: {1} and {2}", diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/ErrorsJs.java b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/ErrorsJs.java index 787eefe04d7..7f8249eb762 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/ErrorsJs.java +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/ErrorsJs.java @@ -41,7 +41,7 @@ public interface ErrorsJs { DiagnosticFactory1 NOT_SUPPORTED = DiagnosticFactory1.create(ERROR, DEFAULT); DiagnosticFactory1 REFERENCE_TO_BUILTIN_MEMBERS_NOT_SUPPORTED = DiagnosticFactory1.create(ERROR, DEFAULT); DiagnosticFactory0 JSCODE_NO_JAVASCRIPT_PRODUCED = DiagnosticFactory0.create(ERROR, DEFAULT); - DiagnosticFactory0 NATIVE_INNER_CLASS_PROHIBITED = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 NESTED_EXTERNAL_DECLARATION = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT); DiagnosticFactory2 JS_NAME_CLASH = DiagnosticFactory2.create( ERROR, DECLARATION_SIGNATURE_OR_DEFAULT); DiagnosticFactory3 JS_FAKE_NAME_CLASH = 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 new file mode 100644 index 00000000000..5f2577f3e3e --- /dev/null +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsExternalChecker.kt @@ -0,0 +1,57 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.js.resolve.diagnostics + +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor +import org.jetbrains.kotlin.diagnostics.DiagnosticSink +import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.js.PredefinedAnnotation +import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils +import org.jetbrains.kotlin.lexer.KtTokens +import org.jetbrains.kotlin.psi.KtDeclaration +import org.jetbrains.kotlin.psi.KtProperty +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.resolve.checkers.SimpleDeclarationChecker + +class JsExternalChecker : SimpleDeclarationChecker { + override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, diagnosticHolder: DiagnosticSink, + bindingContext: BindingContext) { + if (!AnnotationsUtils.isNativeObject(descriptor)) return + + if (!DescriptorUtils.isTopLevelDeclaration(descriptor)) { + if (isDirectlyExternal(declaration, descriptor) && descriptor !is PropertyAccessorDescriptor) { + diagnosticHolder.report(ErrorsJs.NESTED_EXTERNAL_DECLARATION.on(declaration)) + } + } + + if (DescriptorUtils.isAnnotationClass(descriptor)) { + diagnosticHolder.report(Errors.WRONG_MODIFIER_TARGET.on(declaration, KtTokens.EXTERNAL_KEYWORD, "annotation class")) + } + else if (descriptor is PropertyAccessorDescriptor && isDirectlyExternal(declaration, descriptor)) { + diagnosticHolder.report(Errors.WRONG_MODIFIER_TARGET.on(declaration, KtTokens.EXTERNAL_KEYWORD, "property accessor")) + } + } + + private fun isDirectlyExternal(declaration: KtDeclaration, descriptor: DeclarationDescriptor): Boolean { + if (declaration is KtProperty && descriptor is PropertyAccessorDescriptor) return false + + return declaration.hasModifier(KtTokens.EXTERNAL_KEYWORD) || + AnnotationsUtils.hasAnnotation(descriptor, PredefinedAnnotation.NATIVE) + } +} diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/NativeInnerClassChecker.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/NativeInnerClassChecker.kt deleted file mode 100644 index b413c5df8e7..00000000000 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/NativeInnerClassChecker.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.js.resolve.diagnostics - -import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -import org.jetbrains.kotlin.diagnostics.DiagnosticSink -import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils -import org.jetbrains.kotlin.psi.KtDeclaration -import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.resolve.checkers.SimpleDeclarationChecker -import org.jetbrains.kotlin.resolve.DescriptorUtils - -class NativeInnerClassChecker : SimpleDeclarationChecker { - override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, diagnosticHolder: DiagnosticSink, - bindingContext: BindingContext) { - if (descriptor !is ClassDescriptor || !AnnotationsUtils.isNativeObject(descriptor)) return - - if (descriptor.isInner && !AnnotationsUtils.isNativeObject(DescriptorUtils.getContainingClass(descriptor)!!)) { - diagnosticHolder.report(ErrorsJs.NATIVE_INNER_CLASS_PROHIBITED.on(declaration)) - } - } -} diff --git a/js/js.libraries/src/builtins/hacks.kt b/js/js.libraries/src/builtins/hacks.kt index 814f4fa06df..31d7f8a346a 100644 --- a/js/js.libraries/src/builtins/hacks.kt +++ b/js/js.libraries/src/builtins/hacks.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +@file:Suppress("WRONG_MODIFIER_TARGET") package kotlin.js import kotlin.annotation.AnnotationTarget.* diff --git a/js/js.libraries/src/core/annotations.kt b/js/js.libraries/src/core/annotations.kt index 2f0b90afc91..969b2777d89 100644 --- a/js/js.libraries/src/core/annotations.kt +++ b/js/js.libraries/src/core/annotations.kt @@ -20,28 +20,28 @@ import kotlin.annotation.AnnotationTarget.* @Target(CLASS, FUNCTION, PROPERTY, CONSTRUCTOR, VALUE_PARAMETER, PROPERTY_GETTER, PROPERTY_SETTER) @Deprecated("Use `external` modifier instead") -public external annotation class native(@Deprecated public val name: String = "") +public annotation class native(@Deprecated public val name: String = "") @Target(FUNCTION) @Deprecated("Use inline extension function with body using dynamic") -public external annotation class nativeGetter +public annotation class nativeGetter @Target(FUNCTION) @Deprecated("Use inline extension function with body using dynamic") -public external annotation class nativeSetter +public annotation class nativeSetter @Target(FUNCTION) @Deprecated("Use inline extension function with body using dynamic") -public external annotation class nativeInvoke +public annotation class nativeInvoke @Target(CLASS, FUNCTION, PROPERTY) -internal external annotation class library(public val name: String = "") +internal annotation class library(public val name: String = "") @Target(PROPERTY) -public external annotation class enumerable() +public annotation class enumerable() @Target(CLASS) -internal external annotation class marker +internal annotation class marker @Retention(AnnotationRetention.BINARY) @Target(CLASS, FUNCTION, PROPERTY, CONSTRUCTOR, PROPERTY_GETTER, PROPERTY_SETTER) diff --git a/js/js.libraries/src/core/concurrent.kt b/js/js.libraries/src/core/concurrent.kt index 27be0b848f4..822b769287a 100644 --- a/js/js.libraries/src/core/concurrent.kt +++ b/js/js.libraries/src/core/concurrent.kt @@ -29,10 +29,10 @@ package kotlin @Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD) @Retention(AnnotationRetention.SOURCE) -public external annotation class Volatile +public annotation class Volatile @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) @Retention(AnnotationRetention.SOURCE) -public external annotation class Synchronized +public annotation class Synchronized public external inline fun synchronized(lock: Any, crossinline block: () -> R): R = block() diff --git a/js/js.libraries/src/junit/core.kt b/js/js.libraries/src/junit/core.kt index 1f0b35bc68a..ddd5e70d85d 100644 --- a/js/js.libraries/src/junit/core.kt +++ b/js/js.libraries/src/junit/core.kt @@ -1,3 +1,3 @@ package org.junit -public external annotation class Test(val name: String = "") +public annotation class Test(val name: String = "") diff --git a/js/js.translator/testData/box/expression/function/mangling.kt b/js/js.translator/testData/box/expression/function/mangling.kt index aecf906bc1e..82401d1f4dc 100644 --- a/js/js.translator/testData/box/expression/function/mangling.kt +++ b/js/js.translator/testData/box/expression/function/mangling.kt @@ -23,17 +23,22 @@ private external fun private_baz(a: String) { public class PublicClass { public fun public_baz(i: Int) { } - public external fun public_baz(a: String) { + @JsName("public_baz") + public fun public_baz(a: String) { } internal fun internal_baz(i: Int) { } - internal external fun internal_baz(a: String) { + + @JsName("internal_baz") + internal fun internal_baz(a: String) { } private fun private_baz(i: Int) { } - private external fun private_baz(a: String) { + + @JsName("private_baz") + private fun private_baz(a: String) { } val call_private_baz = { private_baz(0) } @@ -43,17 +48,23 @@ public class PublicClass { internal class InternalClass { public fun public_baz(i: Int) { } - public external fun public_baz(a: String) { + + @JsName("public_baz") + public fun public_baz(a: String) { } internal fun internal_baz(i: Int) { } - internal external fun internal_baz(a: String) { + + @JsName("internal_baz") + internal fun internal_baz(a: String) { } private fun private_baz(i: Int) { } - private external fun private_baz(a: String) { + + @JsName("private_baz") + private fun private_baz(a: String) { } val call_private_baz = { private_baz(0) } @@ -63,17 +74,21 @@ internal class InternalClass { private class PrivateClass { public fun public_baz(i: Int) { } - public external fun public_baz(a: String) { + + @JsName("public_baz") + public fun public_baz(a: String) { } internal fun internal_baz(i: Int) { } - internal external fun internal_baz(a: String) { + @JsName("internal_baz") + internal fun internal_baz(a: String) { } private fun private_baz(i: Int) { } - private external fun private_baz(a: String) { + @JsName("private_baz") + private fun private_baz(a: String) { } val call_private_baz = { private_baz(0) } @@ -83,17 +98,20 @@ private class PrivateClass { open public class OpenPublicClass { public fun public_baz(i: Int) { } - public external fun public_baz(a: String) { + @JsName("public_baz") + public fun public_baz(a: String) { } internal fun internal_baz(i: Int) { } - internal external fun internal_baz(a: String) { + @JsName("internal_baz") + internal fun internal_baz(a: String) { } private fun private_baz(i: Int) { } - private external fun private_baz(a: String) { + @JsName("private_baz") + private fun private_baz(a: String) { } val call_private_baz = { private_baz(0) } @@ -103,17 +121,20 @@ open public class OpenPublicClass { internal open class OpenInternalClass { public fun public_baz(i: Int) { } - public external fun public_baz(a: String) { + @JsName("public_baz") + public fun public_baz(a: String) { } internal fun internal_baz(i: Int) { } - internal external fun internal_baz(a: String) { + @JsName("internal_baz") + internal fun internal_baz(a: String) { } private fun private_baz(i: Int) { } - private external fun private_baz(a: String) { + @JsName("private_baz") + private fun private_baz(a: String) { } val call_private_baz = { private_baz(0) } @@ -123,17 +144,20 @@ internal open class OpenInternalClass { open private class OpenPrivateClass { public fun public_baz(i: Int) { } - public external fun public_baz(a: String) { + @JsName("public_baz") + public fun public_baz(a: String) { } internal fun internal_baz(i: Int) { } - internal external fun internal_baz(a: String) { + @JsName("internal_baz") + internal fun internal_baz(a: String) { } private fun private_baz(i: Int) { } - private external fun private_baz(a: String) { + @JsName("private_baz") + private fun private_baz(a: String) { } val call_private_baz = { private_baz(0) } diff --git a/js/js.translator/testData/box/native/classObject.kt b/js/js.translator/testData/box/native/classObject.kt index ad8f530feaa..fc90f3e3565 100644 --- a/js/js.translator/testData/box/native/classObject.kt +++ b/js/js.translator/testData/box/native/classObject.kt @@ -1,8 +1,8 @@ package foo external class A(val c: Int) { - external companion object { - val g: Int = noImpl + companion object { + val g: Int val c: String = noImpl } }