From 92984a37ea0959913f1f82648b957a74939dbcd5 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Mon, 1 Dec 2014 17:17:38 +0300 Subject: [PATCH] Js frontend: prohibit default values for functions annotated as nativeIndexer. --- .../nativeGetter/onLocalExtensionFun.kt | 3 + .../nativeGetter/onLocalNativeClassMembers.kt | 3 + .../onLocalNonNativeClassMembers.kt | 3 + .../nativeGetter/onNativeClassMembers.kt | 3 + .../nativeGetter/onNativeClassMembers.txt | 1 + .../onNestedDeclarationsInsideNativeClass.kt | 9 +++ .../onNestedDeclarationsInsideNativeClass.txt | 3 + ...nNestedDeclarationsInsideNonNativeClass.kt | 9 +++ ...NestedDeclarationsInsideNonNativeClass.txt | 3 + .../nativeGetter/onNonNativeClassMembers.kt | 3 + .../nativeGetter/onNonNativeClassMembers.txt | 1 + .../nativeGetter/onToplevelExtensionFun.kt | 3 + .../nativeGetter/onToplevelExtensionFun.txt | 1 + .../nativeSetter/onLocalExtensionFun.kt | 3 + .../nativeSetter/onLocalNativeClassMembers.kt | 6 ++ .../onLocalNonNativeClassMembers.kt | 3 + .../nativeSetter/onNativeClassMembers.kt | 3 + .../nativeSetter/onNativeClassMembers.txt | 1 + .../onNestedDeclarationsInsideNativeClass.kt | 9 +++ .../onNestedDeclarationsInsideNativeClass.txt | 3 + ...nNestedDeclarationsInsideNonNativeClass.kt | 64 +++++++++++-------- ...NestedDeclarationsInsideNonNativeClass.txt | 5 +- .../nativeSetter/onNonNativeClassMembers.kt | 3 + .../nativeSetter/onNonNativeClassMembers.txt | 1 + .../nativeSetter/onToplevelExtensionFun.kt | 5 +- .../nativeSetter/onToplevelExtensionFun.txt | 1 + .../KotlinJsDeclarationCheckerProvider.kt | 6 ++ .../diagnostics/DefaultErrorMessagesJs.kt | 1 + .../k2js/resolve/diagnostics/ErrorsJs.java | 1 + 29 files changed, 130 insertions(+), 30 deletions(-) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalExtensionFun.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalExtensionFun.kt index 16b80e264a9..423ca603fe3 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalExtensionFun.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalExtensionFun.kt @@ -18,4 +18,7 @@ fun foo() { [nativeGetter] fun Int.get3(a: Any, b: Int, c: Any?): String? = "OK" + + [nativeGetter] + fun Any.foo(a: Int = 1): Any? = "OK" } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNativeClassMembers.kt index 9b34d25a2fe..4b90bfcf2c8 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNativeClassMembers.kt @@ -41,5 +41,8 @@ fun foo() { 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/onLocalNonNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNonNativeClassMembers.kt index 7f84de913a9..41d02f4b6fa 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNonNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNonNativeClassMembers.kt @@ -38,5 +38,8 @@ fun foo() { nativeGetter fun bar(a: String): Int = 0 + + nativeGetter + fun baz(a: Int = 0): Int? = 0 } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.kt index b590c795b36..9ab3a878f95 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.kt @@ -63,6 +63,9 @@ class C { nativeGetter fun bar(a: String): Int = 0 + nativeGetter + fun baz(a: String = "foo"): Int? = 0 + class object { nativeGetter fun Int.get(a: String): Int? = 1 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.txt index ce7d90a6056..af7be8451f8 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.txt @@ -67,6 +67,7 @@ kotlin.js.native() internal final class B { kotlin.js.native() internal final class C { public constructor C() kotlin.js.nativeGetter() internal final fun bar(/*0*/ a: kotlin.String): kotlin.Int + kotlin.js.nativeGetter() internal final fun baz(/*0*/ a: kotlin.String = ...): kotlin.Int? public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean kotlin.js.nativeGetter() internal final fun foo(/*0*/ a: kotlin.Int): kotlin.Unit kotlin.js.nativeGetter() internal final fun get(): kotlin.Any? diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.kt index 373883f6bf3..bcc270a1d36 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.kt @@ -62,6 +62,9 @@ class A { nativeGetter fun bar(a: String): Int = 0 + + nativeGetter + fun baz(a: Number = 1.1): Int? = 0 } object obj { @@ -85,6 +88,9 @@ class A { nativeGetter fun bar(a: String): Int = 0 + + nativeGetter + fun baz(a: String = "foo"): Int? = 0 } val anonymous = object { @@ -108,6 +114,9 @@ class A { 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/onNestedDeclarationsInsideNativeClass.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.txt index d36dd09e4a7..fe4370d5e8b 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.txt @@ -80,6 +80,7 @@ kotlin.js.native() internal final class A { internal final class C { public constructor C() kotlin.js.nativeGetter() internal final fun bar(/*0*/ a: kotlin.String): kotlin.Int + kotlin.js.nativeGetter() internal final fun baz(/*0*/ a: kotlin.Number = ...): kotlin.Int? public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean kotlin.js.nativeGetter() internal final fun foo(/*0*/ a: kotlin.Int): kotlin.Unit kotlin.js.nativeGetter() internal final fun get(): kotlin.Any? @@ -94,6 +95,7 @@ kotlin.js.native() internal final class A { internal object obj { private constructor obj() kotlin.js.nativeGetter() internal final fun bar(/*0*/ a: kotlin.String): kotlin.Int + kotlin.js.nativeGetter() internal final fun baz(/*0*/ a: kotlin.String = ...): kotlin.Int? public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean kotlin.js.nativeGetter() internal final fun foo(/*0*/ a: kotlin.Int): kotlin.Unit kotlin.js.nativeGetter() internal final fun get(): kotlin.Any? @@ -107,6 +109,7 @@ kotlin.js.native() internal final class A { public class object : A.B.obj { private constructor () kotlin.js.nativeGetter() internal final override /*1*/ /*fake_override*/ fun bar(/*0*/ a: kotlin.String): kotlin.Int + kotlin.js.nativeGetter() internal final override /*1*/ /*fake_override*/ fun baz(/*0*/ a: kotlin.String = ...): kotlin.Int? public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean kotlin.js.nativeGetter() internal final override /*1*/ /*fake_override*/ fun foo(/*0*/ a: kotlin.Int): kotlin.Unit kotlin.js.nativeGetter() internal final override /*1*/ /*fake_override*/ fun get(): kotlin.Any? diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNonNativeClass.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNonNativeClass.kt index 67c4c18781f..acec0dc4e2a 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNonNativeClass.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNonNativeClass.kt @@ -70,6 +70,9 @@ class A { nativeGetter fun bar(a: String): Int = 0 + + nativeGetter + fun baz(a: String = "foo"): Int? = 0 } object obj { @@ -84,6 +87,9 @@ class A { nativeGetter fun bar(a: String): Int = 0 + + nativeGetter + fun baz(a: Double = 0.0): Int? = 0 } val anonymous = object { @@ -98,6 +104,9 @@ class A { 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/onNestedDeclarationsInsideNonNativeClass.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNonNativeClass.txt index 7ef09d9751f..ea7ca72b836 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNonNativeClass.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNonNativeClass.txt @@ -86,6 +86,7 @@ internal final class A { internal final class C { public constructor C() kotlin.js.nativeGetter() internal final fun bar(/*0*/ a: kotlin.String): kotlin.Int + kotlin.js.nativeGetter() internal final fun baz(/*0*/ a: kotlin.String = ...): kotlin.Int? public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean kotlin.js.nativeGetter() internal final fun foo(/*0*/ a: kotlin.Int): kotlin.Unit kotlin.js.nativeGetter() internal final fun get(): kotlin.Any? @@ -97,6 +98,7 @@ internal final class A { internal object obj { private constructor obj() kotlin.js.nativeGetter() internal final fun bar(/*0*/ a: kotlin.String): kotlin.Int + kotlin.js.nativeGetter() internal final fun baz(/*0*/ a: kotlin.Double = ...): kotlin.Int? public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean kotlin.js.nativeGetter() internal final fun foo(/*0*/ a: kotlin.Int): kotlin.Unit kotlin.js.nativeGetter() internal final fun get(): kotlin.Any? @@ -107,6 +109,7 @@ internal final class A { public class object : A.B.obj { private constructor () kotlin.js.nativeGetter() internal final override /*1*/ /*fake_override*/ fun bar(/*0*/ a: kotlin.String): kotlin.Int + kotlin.js.nativeGetter() internal final override /*1*/ /*fake_override*/ fun baz(/*0*/ a: kotlin.Double = ...): kotlin.Int? public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean kotlin.js.nativeGetter() internal final override /*1*/ /*fake_override*/ fun foo(/*0*/ a: kotlin.Int): kotlin.Unit kotlin.js.nativeGetter() internal final override /*1*/ /*fake_override*/ fun get(): kotlin.Any? diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNonNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNonNativeClassMembers.kt index e57de8b02b2..9bfd632091b 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNonNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNonNativeClassMembers.kt @@ -59,4 +59,7 @@ class C { 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/onNonNativeClassMembers.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNonNativeClassMembers.txt index 854ddc5e8a2..49648e9f6cd 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNonNativeClassMembers.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNonNativeClassMembers.txt @@ -67,6 +67,7 @@ internal final class B { internal final class C { public constructor C() kotlin.js.nativeGetter() internal final fun bar(/*0*/ a: kotlin.String): kotlin.Int + kotlin.js.nativeGetter() internal final fun baz(/*0*/ a: kotlin.String = ...): kotlin.Int? public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean kotlin.js.nativeGetter() internal final fun foo(/*0*/ a: kotlin.Int): kotlin.Unit kotlin.js.nativeGetter() internal final fun get(): kotlin.Any? diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelExtensionFun.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelExtensionFun.kt index eff01cb22ca..dfafd31f14b 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelExtensionFun.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelExtensionFun.kt @@ -9,6 +9,9 @@ fun Int.get2(a: Number): String? = "OK" nativeGetter fun Int.get3(a: Int): String? = "OK" +nativeGetter +fun Int.baz(a: Int = 0): String? = "OK" + nativeGetter fun Int.get(a: Any): Int? = 1 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelExtensionFun.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelExtensionFun.txt index 1546d308026..3f543c49924 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelExtensionFun.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelExtensionFun.txt @@ -1,5 +1,6 @@ package +kotlin.js.nativeGetter() internal fun kotlin.Int.baz(/*0*/ a: kotlin.Int = ...): kotlin.String? kotlin.js.nativeGetter() internal fun kotlin.Int.get(/*0*/ a: kotlin.Any): kotlin.Int? kotlin.js.nativeGetter() internal fun kotlin.Int.get(/*0*/ a: kotlin.String): kotlin.Int? kotlin.js.nativeGetter() internal fun kotlin.Int.get2(): kotlin.String? diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalExtensionFun.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalExtensionFun.kt index dcb9ee5c63f..d40bd9b50a5 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalExtensionFun.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalExtensionFun.kt @@ -18,4 +18,7 @@ fun foo() { [nativeSetter] fun Int.set3(a: Any, b: Int, c: Any?) {} + + [nativeSetter] + fun Any.foo(a: Double = 0.0, v: String? = null) = "OK" } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNativeClassMembers.kt index 889c5576eb7..2f79ac8a614 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNativeClassMembers.kt @@ -41,5 +41,11 @@ fun foo() { 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/onLocalNonNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNonNativeClassMembers.kt index 4197d4ba1cc..39e9c01a55a 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNonNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNonNativeClassMembers.kt @@ -38,5 +38,8 @@ fun foo() { nativeSetter fun set(a: A, v: Any?) {} + + [nativeSetter] + fun foo(a: Int = 0, v: String) = "OK" } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.kt index 078654d4f04..18792d639ba 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.kt @@ -62,4 +62,7 @@ class C { nativeSetter fun set(a: A, v: Any?) {} + + [nativeSetter] + fun foo(a: Number, v: String = "aa") = "OK" } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.txt index 3bfe87d429a..2ba6ab35092 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.txt @@ -67,6 +67,7 @@ kotlin.js.native() internal final class B { kotlin.js.native() internal final class C { public constructor C() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + kotlin.js.nativeSetter() internal final fun foo(/*0*/ a: kotlin.Number, /*1*/ v: kotlin.String = ...): kotlin.String public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int kotlin.js.nativeSetter() internal final fun set(): kotlin.Any? kotlin.js.nativeSetter() internal final fun set(/*0*/ a: A): kotlin.Any? diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.kt index 3ea5fe1463f..b417ec58a04 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.kt @@ -62,6 +62,9 @@ class A { nativeSetter fun set(a: A, v: Any?) {} + + [nativeSetter] + fun foo(a: Double = 0.0, v: String = "str") = "OK" } object obj { @@ -85,6 +88,9 @@ class A { nativeSetter fun set(a: A, v: Any?) {} + + [nativeSetter] + fun foo(a: Int, v: String = "str") = "OK" } val anonymous = object { @@ -108,6 +114,9 @@ class A { nativeSetter fun set(a: A, v: Any?) {} + + [nativeSetter] + fun foo(a: Number = 0.0, v: String) = "OK" } } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.txt index e67f50a848f..a9f55120c1a 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.txt @@ -80,6 +80,7 @@ kotlin.js.native() internal final class A { internal final class C { public constructor C() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + kotlin.js.nativeSetter() internal final fun foo(/*0*/ a: kotlin.Double = ..., /*1*/ v: kotlin.String = ...): kotlin.String public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int kotlin.js.nativeSetter() internal final fun set(): kotlin.Any? kotlin.js.nativeSetter() internal final fun set(/*0*/ a: A.B.A): kotlin.Any? @@ -94,6 +95,7 @@ kotlin.js.native() internal final class A { internal object obj { private constructor obj() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + kotlin.js.nativeSetter() internal final fun foo(/*0*/ a: kotlin.Int, /*1*/ v: kotlin.String = ...): kotlin.String public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int kotlin.js.nativeSetter() internal final fun set(): kotlin.Any? kotlin.js.nativeSetter() internal final fun set(/*0*/ a: A.B.A): kotlin.Any? @@ -107,6 +109,7 @@ kotlin.js.native() internal final class A { public class object : A.B.obj { private constructor () public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + kotlin.js.nativeSetter() internal final override /*1*/ /*fake_override*/ fun foo(/*0*/ a: kotlin.Int, /*1*/ v: kotlin.String = ...): kotlin.String public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int kotlin.js.nativeSetter() internal final override /*1*/ /*fake_override*/ fun set(): kotlin.Any? kotlin.js.nativeSetter() internal final override /*1*/ /*fake_override*/ fun set(/*0*/ a: A.B.A): kotlin.Any? diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNonNativeClass.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNonNativeClass.kt index 3ea5fe1463f..9537bebf2a8 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNonNativeClass.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNonNativeClass.kt @@ -1,27 +1,26 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER -native class A { class B { class A { - nativeSetter - fun set(a: String, v: Any?): Any? = null + nativeSetter + fun set(a: String, v: Any?): Any? = null - nativeSetter - fun put(a: Number, v: String) {} + nativeSetter + fun put(a: Number, v: String) {} - nativeSetter - fun foo(a: Int, v: String) {} + nativeSetter + fun foo(a: Int, v: String) {} class object { - nativeSetter - fun set(a: String, v: Any?): Any? = null + nativeSetter + fun set(a: String, v: Any?): Any? = null - nativeSetter - fun put(a: Number, v: String) {} + nativeSetter + fun put(a: Number, v: String) {} - nativeSetter - fun foo(a: Int, v: String) {} + nativeSetter + fun foo(a: Int, v: String) {} } } @@ -51,17 +50,20 @@ class A { nativeSetter fun Int.set3(a: Double, v: String?) = "OK" - nativeSetter + nativeSetter fun set(): Any? = null - nativeSetter + nativeSetter fun set(a: A): Any? = null - nativeSetter + nativeSetter fun set(a: String, v: Any, v2: Any) {} - nativeSetter - fun set(a: A, v: Any?) {} + nativeSetter + fun set(a: A, v: Any?) {} + + [nativeSetter] + fun foo(a: Double = 0.0, v: String = "str") = "OK" } object obj { @@ -74,17 +76,20 @@ class A { nativeSetter fun Int.set3(a: Double, v: String?) = "OK" - nativeSetter + nativeSetter fun set(): Any? = null - nativeSetter + nativeSetter fun set(a: A): Any? = null - nativeSetter + nativeSetter fun set(a: String, v: Any, v2: Any) {} - nativeSetter - fun set(a: A, v: Any?) {} + nativeSetter + fun set(a: A, v: Any?) {} + + [nativeSetter] + fun foo(a: Int, v: String = "str") = "OK" } val anonymous = object { @@ -97,17 +102,20 @@ class A { nativeSetter fun Int.set3(a: Double, v: String?) = "OK" - nativeSetter + nativeSetter fun set(): Any? = null - nativeSetter + nativeSetter fun set(a: A): Any? = null - nativeSetter + nativeSetter fun set(a: String, v: Any, v2: Any) {} - nativeSetter - fun set(a: A, v: Any?) {} + nativeSetter + fun set(a: A, v: Any?) {} + + [nativeSetter] + fun foo(a: Number = 0.0, v: String) = "OK" } } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNonNativeClass.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNonNativeClass.txt index e67f50a848f..11a0244c436 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNonNativeClass.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNonNativeClass.txt @@ -1,6 +1,6 @@ package -kotlin.js.native() internal final class A { +internal 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 @@ -80,6 +80,7 @@ kotlin.js.native() internal final class A { internal final class C { public constructor C() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + kotlin.js.nativeSetter() internal final fun foo(/*0*/ a: kotlin.Double = ..., /*1*/ v: kotlin.String = ...): kotlin.String public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int kotlin.js.nativeSetter() internal final fun set(): kotlin.Any? kotlin.js.nativeSetter() internal final fun set(/*0*/ a: A.B.A): kotlin.Any? @@ -94,6 +95,7 @@ kotlin.js.native() internal final class A { internal object obj { private constructor obj() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + kotlin.js.nativeSetter() internal final fun foo(/*0*/ a: kotlin.Int, /*1*/ v: kotlin.String = ...): kotlin.String public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int kotlin.js.nativeSetter() internal final fun set(): kotlin.Any? kotlin.js.nativeSetter() internal final fun set(/*0*/ a: A.B.A): kotlin.Any? @@ -107,6 +109,7 @@ kotlin.js.native() internal final class A { public class object : A.B.obj { private constructor () public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + kotlin.js.nativeSetter() internal final override /*1*/ /*fake_override*/ fun foo(/*0*/ a: kotlin.Int, /*1*/ v: kotlin.String = ...): kotlin.String public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int kotlin.js.nativeSetter() internal final override /*1*/ /*fake_override*/ fun set(): kotlin.Any? kotlin.js.nativeSetter() internal final override /*1*/ /*fake_override*/ fun set(/*0*/ a: A.B.A): kotlin.Any? diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNonNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNonNativeClassMembers.kt index 4710f24b25a..250438dc32e 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNonNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNonNativeClassMembers.kt @@ -59,4 +59,7 @@ class C { nativeSetter fun set(a: A, v: Any?) {} + + [nativeSetter] + fun foo(a: String = "0.0", v: String) = "OK" } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNonNativeClassMembers.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNonNativeClassMembers.txt index 7cdae7dae97..3132ac794ff 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNonNativeClassMembers.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNonNativeClassMembers.txt @@ -67,6 +67,7 @@ internal final class B { internal final class C { public constructor C() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + kotlin.js.nativeSetter() internal final fun foo(/*0*/ a: kotlin.String = ..., /*1*/ v: kotlin.String): kotlin.String public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int kotlin.js.nativeSetter() internal final fun set(): kotlin.Any? kotlin.js.nativeSetter() internal final fun set(/*0*/ a: A): kotlin.Any? diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelExtensionFun.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelExtensionFun.kt index ce37c329dd0..a4bcbd0fe3c 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelExtensionFun.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelExtensionFun.kt @@ -9,6 +9,9 @@ fun Int.set2(a: Number, v: String?) = "OK" nativeSetter fun Int.set3(a: Double, v: String?) = "OK" +[nativeSetter] +fun Any.foo(a: String = "0.0", v: String = "str") = "OK" + nativeSetter fun Int.set(a: A): Int? = 1 @@ -16,4 +19,4 @@ fun Int.set(a: = "OK" nativeSetter -fun Int.set3(a: Any, b: Int, c: Any?) {} +fun Int.set3(a: Any, b: Int, c: Any?) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelExtensionFun.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelExtensionFun.txt index fee7d3394a1..3326236cf5d 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelExtensionFun.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelExtensionFun.txt @@ -1,5 +1,6 @@ package +kotlin.js.nativeSetter() internal fun kotlin.Any.foo(/*0*/ a: kotlin.String = ..., /*1*/ v: kotlin.String = ...): kotlin.String kotlin.js.nativeSetter() internal fun kotlin.Int.set(/*0*/ a: [ERROR : A]): kotlin.Int? kotlin.js.nativeSetter() internal fun kotlin.Int.set(/*0*/ a: kotlin.String, /*1*/ v: kotlin.Int): kotlin.Unit kotlin.js.nativeSetter() internal fun kotlin.Int.set2(): kotlin.String? diff --git a/js/js.frontend/src/org/jetbrains/k2js/resolve/KotlinJsDeclarationCheckerProvider.kt b/js/js.frontend/src/org/jetbrains/k2js/resolve/KotlinJsDeclarationCheckerProvider.kt index a10258217df..b3b65ead444 100644 --- a/js/js.frontend/src/org/jetbrains/k2js/resolve/KotlinJsDeclarationCheckerProvider.kt +++ b/js/js.frontend/src/org/jetbrains/k2js/resolve/KotlinJsDeclarationCheckerProvider.kt @@ -83,6 +83,12 @@ private abstract class AbstractNativeIndexerChecker( if (parameters.size() != requiredParametersCount) { diagnosticHolder.report(ErrorsJs.NATIVE_INDEXER_WRONG_PARAMETER_COUNT.on(declaration, requiredParametersCount, indexerKind)) } + + for (parameter in declaration.getValueParameters()) { + if (parameter.hasDefaultValue()) { + diagnosticHolder.report(ErrorsJs.NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS.on(parameter, indexerKind)) + } + } } } diff --git a/js/js.frontend/src/org/jetbrains/k2js/resolve/diagnostics/DefaultErrorMessagesJs.kt b/js/js.frontend/src/org/jetbrains/k2js/resolve/diagnostics/DefaultErrorMessagesJs.kt index 85e44c29c56..bc0ced6af79 100644 --- a/js/js.frontend/src/org/jetbrains/k2js/resolve/diagnostics/DefaultErrorMessagesJs.kt +++ b/js/js.frontend/src/org/jetbrains/k2js/resolve/diagnostics/DefaultErrorMessagesJs.kt @@ -27,6 +27,7 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by Delegates.lazy { put(ErrorsJs.NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN, "Annotation ''{0}'' is allowed only on member functions of declaration annotated as ''kotlin.js.native'' or on toplevel extension functions", Renderers.RENDER_TYPE) put(ErrorsJs.NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER, "Native {0}''s first parameter type should be ''kotlin.String'' or subtype of ''kotlin.Number''", Renderers.STRING) + put(ErrorsJs.NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS, "Native {0}''s parameter can not have default value", Renderers.STRING) put(ErrorsJs.NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE, "Native getter''s return type should be nullable") put(ErrorsJs.NATIVE_INDEXER_WRONG_PARAMETER_COUNT, "Expected {0} parameters for native {1}", Renderers.TO_STRING, Renderers.STRING) put(ErrorsJs.JSCODE_ERROR, "JavaScript: {0}", Renderers.TO_STRING, Renderers.TO_STRING) diff --git a/js/js.frontend/src/org/jetbrains/k2js/resolve/diagnostics/ErrorsJs.java b/js/js.frontend/src/org/jetbrains/k2js/resolve/diagnostics/ErrorsJs.java index 88d4c69e468..369291f02c1 100644 --- a/js/js.frontend/src/org/jetbrains/k2js/resolve/diagnostics/ErrorsJs.java +++ b/js/js.frontend/src/org/jetbrains/k2js/resolve/diagnostics/ErrorsJs.java @@ -34,6 +34,7 @@ import static org.jetbrains.jet.lang.diagnostics.Severity.WARNING; public interface ErrorsJs { DiagnosticFactory1 NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN = DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT); DiagnosticFactory1 NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER = DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT); + DiagnosticFactory1 NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS = DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT); DiagnosticFactory0 NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE = DiagnosticFactory0.create(ERROR, DECLARATION_RETURN_TYPE); DiagnosticFactory2 NATIVE_INDEXER_WRONG_PARAMETER_COUNT = DiagnosticFactory2.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT); DiagnosticFactory2> JSCODE_ERROR = DiagnosticFactory2.create(ERROR, JsCodePositioningStrategy.INSTANCE$);