From 3882bf7564d71cf056cbc7c47ac6952a9565f2e9 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 28 Nov 2016 11:38:29 +0300 Subject: [PATCH] JS: prohibit native (external) extension properties and functions. See KT-13896 --- .../native/extensionFunctionAndProperty.kt | 10 +++++ .../native/extensionFunctionAndProperty.txt | 12 ++++++ .../nativeGetter/onNativeClassMembers.kt | 20 ---------- .../nativeGetter/onNativeClassMembers.txt | 13 ------- .../onNestedDeclarationsInsideNativeClass.kt | 27 ------------- .../onNestedDeclarationsInsideNativeClass.txt | 6 --- .../nativeInvoke/onNativeClassMembers.kt | 12 ------ .../nativeInvoke/onNativeClassMembers.txt | 4 -- .../onNestedDeclarationsInsideNativeClass.kt | 12 ------ .../onNestedDeclarationsInsideNativeClass.txt | 4 -- .../nativeSetter/onNativeClassMembers.kt | 9 ----- .../nativeSetter/onNativeClassMembers.txt | 3 -- .../onNestedDeclarationsInsideNativeClass.kt | 27 ------------- .../onNestedDeclarationsInsideNativeClass.txt | 6 --- .../testsWithJsStdLib/native/nested.kt | 6 --- .../testsWithJsStdLib/native/nested.txt | 3 -- .../native/optionlBody/native.kt | 5 --- .../native/optionlBody/native.txt | 3 -- .../native/unusedParam/native.kt | 2 - .../native/unusedParam/native.txt | 1 - .../DiagnosticsTestWithJsStdLibGenerated.java | 6 +++ .../resolve/diagnostics/JsExternalChecker.kt | 12 ++++++ .../js/test/semantics/BoxJsTestGenerated.java | 24 ------------ ...closureThisByUsingMethodFromParentClass.kt | 20 ++-------- .../box/expression/function/_common.kt | 4 +- .../box/inheritance/overrideAnyMethods.kt | 2 +- .../box/inline/arrayLiteralAliasing.kt | 4 +- .../testData/box/native/kt1519.js | 8 ---- .../testData/box/native/kt1519.kt | 17 -------- .../box/native/nativeExtensionLikeMember.js | 5 --- .../box/native/nativeExtensionLikeMember.kt | 39 ------------------- .../native/nativePropertyWithCustomName.js | 1 - .../native/nativePropertyWithCustomName.kt | 32 --------------- .../box/native/passMemberOrExtFromNative.kt | 11 ------ .../testData/box/native/vararg.kt | 7 ---- .../nativePropertiesNameClashes.kt | 17 -------- 36 files changed, 48 insertions(+), 346 deletions(-) create mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.kt create mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.txt delete mode 100644 js/js.translator/testData/box/native/kt1519.js delete mode 100644 js/js.translator/testData/box/native/kt1519.kt delete mode 100644 js/js.translator/testData/box/native/nativeExtensionLikeMember.js delete mode 100644 js/js.translator/testData/box/native/nativeExtensionLikeMember.kt delete mode 100644 js/js.translator/testData/box/native/nativePropertyWithCustomName.js delete mode 100644 js/js.translator/testData/box/native/nativePropertyWithCustomName.kt delete mode 100644 js/js.translator/testData/box/propertyAccess/nativePropertiesNameClashes.kt diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.kt new file mode 100644 index 00000000000..c36054ff069 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.kt @@ -0,0 +1,10 @@ +class A + +external fun A.foo(): Unit = noImpl + +external var A.bar: String + get() = noImpl + set(value) = noImpl + +external val A.baz: String + get() = noImpl \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.txt new file mode 100644 index 00000000000..d4206896ce1 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.txt @@ -0,0 +1,12 @@ +package + +public external var A.bar: kotlin.String +public external val A.baz: kotlin.String +public external fun A.foo(): kotlin.Unit + +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 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.kt index 46a446fb5ac..2964529646b 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.kt @@ -39,15 +39,6 @@ external class B { } 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 @@ -63,15 +54,4 @@ external class C { @nativeGetter fun baz(a: String = "foo"): Int? = 0 - companion object { - @nativeGetter - fun Int.get(a: String): Int? = 1 - - @nativeGetter - fun Int.get2(a: Number): String? = "OK" - - @nativeGetter - fun Int.get3(a: Int): String? = "OK" - } - } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.txt index a22d7d459c1..1a14273103c 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.txt @@ -60,17 +60,4 @@ public external final class C { @kotlin.js.nativeGetter public final fun get(/*0*/ a: A): kotlin.Any? public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String - @kotlin.js.nativeGetter public final fun kotlin.Int.get(/*0*/ a: kotlin.String): kotlin.Int? - @kotlin.js.nativeGetter public final fun kotlin.Int.get2(/*0*/ a: kotlin.Number): kotlin.String? - @kotlin.js.nativeGetter public final fun kotlin.Int.get3(/*0*/ a: kotlin.Int): kotlin.String? - - public companion object Companion { - private constructor Companion() - 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.nativeGetter public final fun kotlin.Int.get(/*0*/ a: kotlin.String): kotlin.Int? - @kotlin.js.nativeGetter public final fun kotlin.Int.get2(/*0*/ a: kotlin.Number): kotlin.String? - @kotlin.js.nativeGetter public final fun kotlin.Int.get3(/*0*/ a: kotlin.Int): kotlin.String? - } } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.kt index c3b288b829b..ce813f9e666 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.kt @@ -41,15 +41,6 @@ external class A { } 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 @@ -67,15 +58,6 @@ external class A { } object obj { - @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 @@ -93,15 +75,6 @@ external class A { } val anonymous = object { - @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 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.txt index d10cf67e7ed..7493ed41496 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.txt @@ -73,9 +73,6 @@ public external final class A { @kotlin.js.nativeGetter public final fun get(/*0*/ a: A.B.A): kotlin.Any? public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String - @kotlin.js.nativeGetter public final fun kotlin.Int.get(/*0*/ a: kotlin.String): kotlin.Int? - @kotlin.js.nativeGetter public final fun kotlin.Int.get2(/*0*/ a: kotlin.Number): kotlin.String? - @kotlin.js.nativeGetter public final fun kotlin.Int.get3(/*0*/ a: kotlin.Int): kotlin.String? } public object obj { @@ -88,9 +85,6 @@ public external final class A { @kotlin.js.nativeGetter public final fun get(/*0*/ a: A.B.A): kotlin.Any? public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String - @kotlin.js.nativeGetter public final fun kotlin.Int.get(/*0*/ a: kotlin.String): kotlin.Int? - @kotlin.js.nativeGetter public final fun kotlin.Int.get2(/*0*/ a: kotlin.Number): kotlin.String? - @kotlin.js.nativeGetter public final fun kotlin.Int.get3(/*0*/ a: kotlin.Int): kotlin.String? } } } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.kt index 0a3dc35f6ca..4b352e132b9 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.kt @@ -7,12 +7,6 @@ external class A { @nativeInvoke fun invoke(a: String): Int = 0 - @nativeInvoke - fun Int.ext() = 1 - - @nativeInvoke - fun Int.invoke(a: String, b: Int) = "OK" - @nativeInvoke val foo = 0 @@ -26,12 +20,6 @@ external class A { @nativeInvoke fun invoke(a: String): Int = 0 - @nativeInvoke - fun Int.ext() = 1 - - @nativeInvoke - fun Int.invoke(a: String, b: Int) = "OK" - @nativeInvoke val foo = 0 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.txt index 25aa2f7e279..7385d06aeff 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.txt @@ -8,8 +8,6 @@ public external final class A { public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int @kotlin.js.nativeInvoke public final fun invoke(/*0*/ a: kotlin.String): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String - @kotlin.js.nativeInvoke public final fun kotlin.Int.ext(): kotlin.Int - @kotlin.js.nativeInvoke public final fun kotlin.Int.invoke(/*0*/ a: kotlin.String, /*1*/ b: kotlin.Int): kotlin.String public companion object Companion { private constructor Companion() @@ -19,8 +17,6 @@ public external final class A { public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int @kotlin.js.nativeInvoke public final fun invoke(/*0*/ a: kotlin.String): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String - @kotlin.js.nativeInvoke public final fun kotlin.Int.ext(): kotlin.Int - @kotlin.js.nativeInvoke public final fun kotlin.Int.invoke(/*0*/ a: kotlin.String, /*1*/ b: kotlin.Int): kotlin.String @kotlin.js.nativeInvoke public object Obj2 { private constructor Obj2() diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.kt index 023421f2487..057924be321 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.kt @@ -8,12 +8,6 @@ external class A { @nativeInvoke fun invoke(a: String): Int = 0 - - @nativeInvoke - fun Int.ext() = 1 - - @nativeInvoke - fun Int.invoke(a: String, b: Int) = "OK" } object obj { @@ -22,12 +16,6 @@ external class A { @nativeInvoke fun invoke(a: String): Int = 0 - - @nativeInvoke - fun Int.ext() = 1 - - @nativeInvoke - fun Int.invoke(a: String, b: Int) = "OK" } companion object { diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.txt index 42aa11a6319..b665846638f 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.txt @@ -20,8 +20,6 @@ public external final class A { public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int @kotlin.js.nativeInvoke public final fun invoke(/*0*/ a: kotlin.String): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String - @kotlin.js.nativeInvoke public final fun kotlin.Int.ext(): kotlin.Int - @kotlin.js.nativeInvoke public final fun kotlin.Int.invoke(/*0*/ a: kotlin.String, /*1*/ b: kotlin.Int): kotlin.String } public companion object Companion { @@ -40,8 +38,6 @@ public external final class A { public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int @kotlin.js.nativeInvoke public final fun invoke(/*0*/ a: kotlin.String): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String - @kotlin.js.nativeInvoke public final fun kotlin.Int.ext(): kotlin.Int - @kotlin.js.nativeInvoke public final fun kotlin.Int.invoke(/*0*/ a: kotlin.String, /*1*/ b: kotlin.Int): kotlin.String } } } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.kt index 9edb1940da7..42aca651511 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.kt @@ -51,15 +51,6 @@ external class B { } external 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 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.txt index fa2cb7249a5..02255dee7c8 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.txt @@ -65,7 +65,4 @@ public external final class C { @kotlin.js.nativeSetter public final fun set(/*0*/ a: kotlin.String, /*1*/ v: kotlin.Any, /*2*/ v2: kotlin.Any): kotlin.Unit @kotlin.js.nativeSetter public final fun set6(/*0*/ a: kotlin.Double, /*1*/ v: kotlin.String): kotlin.Number public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String - @kotlin.js.nativeSetter public final fun kotlin.Int.set(/*0*/ a: kotlin.String, /*1*/ v: kotlin.Int): kotlin.Unit - @kotlin.js.nativeSetter public final fun kotlin.Int.set2(/*0*/ a: kotlin.Number, /*1*/ v: kotlin.String?): kotlin.String - @kotlin.js.nativeSetter public final fun kotlin.Int.set3(/*0*/ a: kotlin.Double, /*1*/ v: kotlin.String?): kotlin.String } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.kt index eb57f9c8617..46c944bd52b 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.kt @@ -53,15 +53,6 @@ external class A { } 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 @@ -82,15 +73,6 @@ external class A { } object obj { - @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 set(): Any? = null @@ -108,15 +90,6 @@ external class A { } val anonymous = object { - @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 set(): Any? = null diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.txt index 8f4b0dea460..939702c6e39 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.txt @@ -78,9 +78,6 @@ public external final class A { @kotlin.js.nativeSetter public final fun set(/*0*/ a: kotlin.String, /*1*/ v: kotlin.Any, /*2*/ v2: kotlin.Any): kotlin.Unit @kotlin.js.nativeSetter public final fun set6(/*0*/ a: kotlin.Double, /*1*/ v: kotlin.String): kotlin.Number public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String - @kotlin.js.nativeSetter public final fun kotlin.Int.set(/*0*/ a: kotlin.String, /*1*/ v: kotlin.Int): kotlin.Unit - @kotlin.js.nativeSetter public final fun kotlin.Int.set2(/*0*/ a: kotlin.Number, /*1*/ v: kotlin.String?): kotlin.String - @kotlin.js.nativeSetter public final fun kotlin.Int.set3(/*0*/ a: kotlin.Double, /*1*/ v: kotlin.String?): kotlin.String } public object obj { @@ -93,9 +90,6 @@ public external final class A { @kotlin.js.nativeSetter public final fun set(/*0*/ a: A.B.A, /*1*/ v: kotlin.Any?): kotlin.Unit @kotlin.js.nativeSetter public final fun set(/*0*/ a: kotlin.String, /*1*/ v: kotlin.Any, /*2*/ v2: kotlin.Any): kotlin.Unit public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String - @kotlin.js.nativeSetter public final fun kotlin.Int.set(/*0*/ a: kotlin.String, /*1*/ v: kotlin.Int): kotlin.Unit - @kotlin.js.nativeSetter public final fun kotlin.Int.set2(/*0*/ a: kotlin.Number, /*1*/ v: kotlin.String?): kotlin.String - @kotlin.js.nativeSetter public final fun kotlin.Int.set3(/*0*/ a: kotlin.Double, /*1*/ v: kotlin.String?): kotlin.String } } } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.kt index 88aa254b561..7bf2a09e1ca 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.kt @@ -17,8 +17,6 @@ class TopLevel { external val y: String val O.u: String get() = "O.u" - - external val O.v: String get() = noImpl } external class TopLevelNative { @@ -33,10 +31,6 @@ external class TopLevelNative { val x = "a" external val y: String - - val O.u: String get() = "O.u" - - external val O.v: String get() = noImpl } fun topLevelFun() { diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.txt index 561329c550f..73dc68c4d06 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.txt @@ -14,7 +14,6 @@ public final class TopLevel { public final val x: kotlin.String = "a" public external final val y: kotlin.String public final val O.u: kotlin.String - public external 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 @@ -41,8 +40,6 @@ public external final class TopLevelNative { public constructor TopLevelNative() public final val x: kotlin.String = "a" public external final val y: kotlin.String - public final val O.u: kotlin.String - public external 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 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.kt index eaded577aac..968012954f0 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.kt @@ -4,14 +4,9 @@ external val baz: Int external val boo: Int = noImpl -external val Int.baz: Int - external fun foo() external fun bar() {} -external fun String.foo(): Int -external fun String.bar(): Int = noImpl - external interface T { val baz: Int diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.txt index c1233e16682..f68e2bd7756 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.txt @@ -2,11 +2,8 @@ package public external val baz: kotlin.Int public external val boo: kotlin.Int -public external val kotlin.Int.baz: kotlin.Int public external fun bar(): kotlin.Unit public external fun foo(): kotlin.Unit -public external fun kotlin.String.bar(): kotlin.Int -public external fun kotlin.String.foo(): kotlin.Int public external final class C { public constructor C() diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/native.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/native.kt index 50090fcf041..c9dcb24ff9f 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/native.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/native.kt @@ -1,7 +1,5 @@ external fun foo(a: String): Int = noImpl -external fun Int.foo(a: String): Int = noImpl - external class Bar(b: Int, c: Char) { fun baz(d: Int) {} } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/native.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/native.txt index fee4eb7387d..904c4b3fe66 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/native.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/native.txt @@ -1,7 +1,6 @@ package public external fun foo(/*0*/ a: kotlin.String): kotlin.Int -public external fun kotlin.Int.foo(/*0*/ a: kotlin.String): kotlin.Int public external final class Bar { public constructor Bar(/*0*/ b: kotlin.Int, /*1*/ c: kotlin.Char) diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java index 9aecea11635..be7b2aff1d5 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java @@ -527,6 +527,12 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithJsStdLib/native"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("extensionFunctionAndProperty.kt") + public void testExtensionFunctionAndProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.kt"); + doTest(fileName); + } + @TestMetadata("nested.kt") public void testNested() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/nested.kt"); 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 5f2577f3e3e..ed016b79534 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 @@ -17,7 +17,9 @@ package org.jetbrains.kotlin.js.resolve.diagnostics import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.diagnostics.DiagnosticSink import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.js.PredefinedAnnotation @@ -28,6 +30,7 @@ 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 +import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension class JsExternalChecker : SimpleDeclarationChecker { override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, diagnosticHolder: DiagnosticSink, @@ -46,6 +49,15 @@ class JsExternalChecker : SimpleDeclarationChecker { else if (descriptor is PropertyAccessorDescriptor && isDirectlyExternal(declaration, descriptor)) { diagnosticHolder.report(Errors.WRONG_MODIFIER_TARGET.on(declaration, KtTokens.EXTERNAL_KEYWORD, "property accessor")) } + + if (descriptor !is PropertyAccessorDescriptor && descriptor.isExtension) { + val target = when (descriptor) { + is FunctionDescriptor -> "extension function" + is PropertyDescriptor -> "extension property" + else -> "extension member" + } + diagnosticHolder.report(Errors.WRONG_MODIFIER_TARGET.on(declaration, KtTokens.EXTERNAL_KEYWORD, target)) + } } private fun isDirectlyExternal(declaration: KtDeclaration, descriptor: DeclarationDescriptor): Boolean { diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java index 312947d5541..db43bbb664f 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java @@ -5639,12 +5639,6 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { doTest(fileName); } - @TestMetadata("kt1519.kt") - public void testKt1519() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/native/kt1519.kt"); - doTest(fileName); - } - @TestMetadata("kt2209.kt") public void testKt2209() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/native/kt2209.kt"); @@ -5669,12 +5663,6 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { doTest(fileName); } - @TestMetadata("nativeExtensionLikeMember.kt") - public void testNativeExtensionLikeMember() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/native/nativeExtensionLikeMember.kt"); - doTest(fileName); - } - @TestMetadata("nativeGetterAndNativeSetter.kt") public void testNativeGetterAndNativeSetter() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/native/nativeGetterAndNativeSetter.kt"); @@ -5687,12 +5675,6 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { doTest(fileName); } - @TestMetadata("nativePropertyWithCustomName.kt") - public void testNativePropertyWithCustomName() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/native/nativePropertyWithCustomName.kt"); - doTest(fileName); - } - @TestMetadata("nestedElements.kt") public void testNestedElements() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/native/nestedElements.kt"); @@ -6314,12 +6296,6 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { doTest(fileName); } - @TestMetadata("nativePropertiesNameClashes.kt") - public void testNativePropertiesNameClashes() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/propertyAccess/nativePropertiesNameClashes.kt"); - doTest(fileName); - } - @TestMetadata("overloadedOverriddenFunctionPropertyName.kt") public void testOverloadedOverriddenFunctionPropertyName() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/propertyAccess/overloadedOverriddenFunctionPropertyName.kt"); diff --git a/js/js.translator/testData/box/closure/closureThisByUsingMethodFromParentClass.kt b/js/js.translator/testData/box/closure/closureThisByUsingMethodFromParentClass.kt index 7d2cb3583b6..1d4e918e2dd 100644 --- a/js/js.translator/testData/box/closure/closureThisByUsingMethodFromParentClass.kt +++ b/js/js.translator/testData/box/closure/closureThisByUsingMethodFromParentClass.kt @@ -1,19 +1,5 @@ package foo -// HACKS - -external const val PATH_TO_F_CREATOR = "B\$far\$lambda" -external const val PATH_TO_G_CREATOR = "B\$gar\$lambda" - -@JsName("$PATH_TO_F_CREATOR") -external val F_CREATOR: Any = noImpl - -@JsName("$PATH_TO_G_CREATOR") -external val G_CREATOR: Any = noImpl - - -// Test - open class A { fun foo() = "A::foo" } @@ -34,8 +20,8 @@ fun box(): String { assertEquals("A::foo", f()) assertEquals("B::boo", g()) - val fs = F_CREATOR.toString() - val gs = G_CREATOR.toString().replaceAll("boo", "foo").replaceAll("gar", "far") + val fs = js("B\$far\$lambda").toString() as String + val gs = (js("B\$gar\$lambda").toString() as String).replaceAll("boo", "foo").replaceAll("gar", "far") assertEquals(gs, fs) @@ -45,7 +31,7 @@ fun box(): String { // Helpers -external fun String.replace(regexp: RegExp, replacement: String): String = noImpl +inline fun String.replace(regexp: RegExp, replacement: String): String = asDynamic().replace(regexp, replacement) fun String.replaceAll(regexp: String, replacement: String): String = replace(RegExp(regexp, "g"), replacement) diff --git a/js/js.translator/testData/box/expression/function/_common.kt b/js/js.translator/testData/box/expression/function/_common.kt index 73d18c9a97f..171e96fbd4b 100644 --- a/js/js.translator/testData/box/expression/function/_common.kt +++ b/js/js.translator/testData/box/expression/function/_common.kt @@ -1,10 +1,10 @@ package foo -external fun String.replace(regexp: RegExp, replacement: String): String = noImpl +inline fun String.replace(regexp: RegExp, replacement: String): String = asDynamic().replace(regexp, replacement) fun String.replaceAll(regexp: String, replacement: String): String = replace(RegExp(regexp, "g"), replacement) -external fun String.search(regexp: RegExp): Int = noImpl +inline fun String.search(regexp: RegExp): Int = asDynamic().search(regexp) external class RegExp(regexp: String, flags: String = "") { fun exec(s: String): Array? = noImpl diff --git a/js/js.translator/testData/box/inheritance/overrideAnyMethods.kt b/js/js.translator/testData/box/inheritance/overrideAnyMethods.kt index 8c31cb29d8b..1b16eb30418 100644 --- a/js/js.translator/testData/box/inheritance/overrideAnyMethods.kt +++ b/js/js.translator/testData/box/inheritance/overrideAnyMethods.kt @@ -1,6 +1,6 @@ package foo -external fun String.charCodeAt(i: Int): Int = noImpl +inline fun String.charCodeAt(i: Int): Int = asDynamic().charCodeAt(i) // Because String in JS doesn't have hashCode method fun String.myHashCode(): Int { diff --git a/js/js.translator/testData/box/inline/arrayLiteralAliasing.kt b/js/js.translator/testData/box/inline/arrayLiteralAliasing.kt index 1d5f2c37db6..0fed06b0cda 100644 --- a/js/js.translator/testData/box/inline/arrayLiteralAliasing.kt +++ b/js/js.translator/testData/box/inline/arrayLiteralAliasing.kt @@ -28,9 +28,9 @@ package foo // CHECK_NOT_CALLED: moveTo -external fun Array.push(element: Int): Unit = noImpl +inline fun Array.push(element: Int): Unit = asDynamic().push(element) -external fun Array.splice(index: Int, howMany: Int): Unit = noImpl +inline fun Array.splice(index: Int, howMany: Int): Unit = asDynamic().splice(index, howMany) data class PairArray(val fst: Array, val snd: Array) diff --git a/js/js.translator/testData/box/native/kt1519.js b/js/js.translator/testData/box/native/kt1519.js deleted file mode 100644 index 7f8e96e7539..00000000000 --- a/js/js.translator/testData/box/native/kt1519.js +++ /dev/null @@ -1,8 +0,0 @@ -function Wow() { - this.x = 1; - this.y = 2; -} - -Wow.prototype.sum = function () { - return this.x + this.y; -}; \ No newline at end of file diff --git a/js/js.translator/testData/box/native/kt1519.kt b/js/js.translator/testData/box/native/kt1519.kt deleted file mode 100644 index efaa96b93da..00000000000 --- a/js/js.translator/testData/box/native/kt1519.kt +++ /dev/null @@ -1,17 +0,0 @@ -package foo - -external class Wow() { - val x: Int = noImpl - val y: Int = noImpl -} - -external fun Wow.sum(): Int = noImpl - -fun Wow.dblSum(): Int { - return 2 * sum() -} - - -fun box(): String { - return if (Wow().dblSum() == 6) "OK" else "fail" -} diff --git a/js/js.translator/testData/box/native/nativeExtensionLikeMember.js b/js/js.translator/testData/box/native/nativeExtensionLikeMember.js deleted file mode 100644 index a14d72e39e1..00000000000 --- a/js/js.translator/testData/box/native/nativeExtensionLikeMember.js +++ /dev/null @@ -1,5 +0,0 @@ -function A(value) { - this.value = value; -} - -A.prototype.bar = function() { return "A.bar " + this.value; }; diff --git a/js/js.translator/testData/box/native/nativeExtensionLikeMember.kt b/js/js.translator/testData/box/native/nativeExtensionLikeMember.kt deleted file mode 100644 index 88db35ac9ae..00000000000 --- a/js/js.translator/testData/box/native/nativeExtensionLikeMember.kt +++ /dev/null @@ -1,39 +0,0 @@ -package foo - -external open class A(val value: String) { -} - -class B : A("B") { - fun bar(): String = "B.bar ${value}" - var prop: String = "B prop" -} - -external fun A.bar(): String = noImpl - -external var A.prop: String - get() = noImpl - set(value) = noImpl - -fun box(): String { - var a: A = A("A") - val b: B = B() - - assertEquals("A.bar A", a.bar()) - assertEquals("B.bar B", b.bar()) - - assertEquals("A.bar A", (A::bar)(a)) - assertEquals("B.bar B", (A::bar)(b)) - - a.prop = "prop" - assertEquals("prop", a.prop) - assertEquals("prop", (A::prop).get(a)) - - a = b - assertEquals("B.bar B", a.bar()) - assertEquals("B.bar B", (A::bar)(a)) - - assertEquals("B prop", a.prop) - assertEquals("B prop", (A::prop).get(a)) - - return "OK" -} diff --git a/js/js.translator/testData/box/native/nativePropertyWithCustomName.js b/js/js.translator/testData/box/native/nativePropertyWithCustomName.js deleted file mode 100644 index 14cbfbbf3af..00000000000 --- a/js/js.translator/testData/box/native/nativePropertyWithCustomName.js +++ /dev/null @@ -1 +0,0 @@ -var boo = "K"; \ No newline at end of file diff --git a/js/js.translator/testData/box/native/nativePropertyWithCustomName.kt b/js/js.translator/testData/box/native/nativePropertyWithCustomName.kt deleted file mode 100644 index 2a1bb9eeb1d..00000000000 --- a/js/js.translator/testData/box/native/nativePropertyWithCustomName.kt +++ /dev/null @@ -1,32 +0,0 @@ -package foo - -// TODO: this feature is deprecated, remove this test when either @native annotation or its parameter get eliminated. - -internal @native("\"O\"") val foo: String = noImpl -internal @native("boo") val bar: String = noImpl - -internal class A -internal @native("__proto__") val Any.proto: String get() = noImpl -internal @native("__proto__") val A.proto: String get() = noImpl - -internal fun actual(foo: String, @native("boo") bar: String) = foo + bar -internal fun expected(foo: String, boo: String) = foo + boo - -fun box(): String { - val OK = "OK" - - if (foo + bar != OK) return "$foo + $bar != $OK" - - val actualAsString = js("actual").toString() - val expectedAsString = js("expected").toString().replace("expected", "actual") - if (actualAsString != expectedAsString) return "$actualAsString != $expectedAsString" - if (actual("asd", "12345") != "asd12345") return "${actual("asd", "12345")} != \"asd12345\"" - - val a = A() - val any: Any = a - val protoA = A::class.js.asDynamic().prototype - if (a.proto != any.proto || a.proto != protoA) - return "a.proto != any.proto /*${a.proto != any.proto}*/ || a.proto != A.prototype /*${a.proto != protoA}*/" - - return OK -} diff --git a/js/js.translator/testData/box/native/passMemberOrExtFromNative.kt b/js/js.translator/testData/box/native/passMemberOrExtFromNative.kt index 3452ef7377b..974fac088e5 100644 --- a/js/js.translator/testData/box/native/passMemberOrExtFromNative.kt +++ b/js/js.translator/testData/box/native/passMemberOrExtFromNative.kt @@ -4,11 +4,6 @@ external class A(val v: String) { fun m(i:Int, s:String): String = noImpl } -external fun A.nativeExt(i:Int, s:String): String = noImpl - -@JsName("nativeExt2AnotherName") -external fun A.nativeExt2(i:Int, s:String): String = noImpl - fun bar(a: A, extLambda: A.(Int, String) -> String): String = a.(extLambda)(4, "boo") fun box(): String { @@ -17,11 +12,5 @@ fun box(): String { assertEquals("A.m test 4 boo", a.m(4, "boo")) assertEquals("A.m test 4 boo", bar(a, fun A.(i, s) = (A::m)(this, i, s))) - assertEquals("nativeExt test 4 boo", a.nativeExt(4, "boo")) - assertEquals("nativeExt test 4 boo", bar(a, fun A.(i, s) = (A::nativeExt)(this, i, s))) - - assertEquals("nativeExt2 test 4 boo", a.nativeExt2(4, "boo")) - assertEquals("nativeExt2 test 4 boo", bar(a, fun A.(i, s) = (A::nativeExt2)(this, i, s))) - return "OK" } diff --git a/js/js.translator/testData/box/native/vararg.kt b/js/js.translator/testData/box/native/vararg.kt index 416c88c1a56..7de8e081d36 100644 --- a/js/js.translator/testData/box/native/vararg.kt +++ b/js/js.translator/testData/box/native/vararg.kt @@ -16,8 +16,6 @@ fun anotherCount(vararg a: Int) = anotherParamCount(*a) external fun test3(bar: Bar, dummy: Int, vararg args: Int): Boolean = noImpl -external fun Bar.test2(order: Int, dummy: Int, vararg args: Int): Boolean = noImpl - external class Bar(val size: Int, order: Int = 0) { fun test(order: Int, dummy: Int, vararg args: Int): Boolean = noImpl companion object { @@ -34,8 +32,6 @@ fun spreadInMethodCall(size: Int, vararg args: Int) = Bar(size).test(0, 1, *args fun spreadInObjectMethodCall(size: Int, vararg args: Int) = obj.test(size, *args) -fun spreadInMethodCallWithReceiver(size: Int, vararg args: Int) = Bar(size).test2(0, 1, *args) - fun spreadInPackageMethodCall(size: Int, vararg args: Int) = test3(Bar(size), 1, *args) external fun testNativeVarargWithFunLit(vararg args: Int, f: (a: IntArray) -> Boolean): Boolean = noImpl @@ -98,9 +94,6 @@ fun box(): String { if (!(spreadInObjectMethodCall(2, 1, 2))) return "failed when call method of object using spread operator" - if (!spreadInMethodCallWithReceiver(2, 1, 2)) - return "failed when call method using spread operator with receiver" - if (!spreadInPackageMethodCall(2, 1, 2)) return "failed when call package method using spread operator" diff --git a/js/js.translator/testData/box/propertyAccess/nativePropertiesNameClashes.kt b/js/js.translator/testData/box/propertyAccess/nativePropertiesNameClashes.kt deleted file mode 100644 index 2afc10baaf5..00000000000 --- a/js/js.translator/testData/box/propertyAccess/nativePropertiesNameClashes.kt +++ /dev/null @@ -1,17 +0,0 @@ -package foo - -val PACKAGE = "kotlin.modules.JS_TESTS.foo" - -class A -external val Any.__proto__: String get() = noImpl -external val A.__proto__: String get() = noImpl - -fun box(): String { - val a = A() - val any: Any = a - val protoA = eval("$PACKAGE.A.prototype") - if (a.__proto__ != any.__proto__ || a.__proto__ != protoA) - return "a.__proto__ != any.__proto__ /*${a.__proto__ != any.__proto__}*/ || a.__proto__ != $PACKAGE.A.prototype /*${a.__proto__ != protoA}*/" - - return "OK" -}