diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/module/nestedProhibited.kt b/compiler/testData/diagnostics/testsWithJsStdLib/module/nestedProhibited.kt index c7ad3dddb95..501471682a1 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/module/nestedProhibited.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/module/nestedProhibited.kt @@ -8,10 +8,10 @@ external class A external object B @JsModule("foo") -external fun foo() = 23 +external fun foo(): Int @JsModule("bar") -external val bar = 42 +external val bar: Int @JsNonModule -external val baz = 99 \ No newline at end of file +external val baz: Int \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/module/nestedProhibited.txt b/compiler/testData/diagnostics/testsWithJsStdLib/module/nestedProhibited.txt index 7b0f5f3f911..11dee24c214 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/module/nestedProhibited.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/module/nestedProhibited.txt @@ -1,8 +1,8 @@ package package foo { - @kotlin.js.JsModule(import = "bar") public external val bar: kotlin.Int = 42 - @kotlin.js.JsNonModule public external val baz: kotlin.Int = 99 + @kotlin.js.JsModule(import = "bar") public external val bar: kotlin.Int + @kotlin.js.JsNonModule public external val baz: kotlin.Int @kotlin.js.JsModule(import = "foo") public external fun foo(): kotlin.Int @kotlin.js.JsModule(import = "A") public external final class A { diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/body.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/body.kt new file mode 100644 index 00000000000..c8008fc6734 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/body.kt @@ -0,0 +1,30 @@ +external fun foo(): Int = noImpl + +external fun bar(): Unit { + noImpl +} + +external fun baz(): Int = 23 + +external fun f(x: Int, y: String = noImpl): Unit + +external fun g(x: Int, y: String = ""): Unit + +external var a: Int + get() = noImpl + set(value) { + noImpl + } + +external val b: Int + get() = 23 + +external val c: Int = noImpl + +external val d: Int = 23 + +external class C { + fun foo(): Int = noImpl + + fun bar(): Int = 23 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/body.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/body.txt new file mode 100644 index 00000000000..063848a5b8d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/body.txt @@ -0,0 +1,20 @@ +package + +public external var a: kotlin.Int +public external val b: kotlin.Int +public external val c: kotlin.Int +public external val d: kotlin.Int = 23 +public external fun bar(): kotlin.Unit +public external fun baz(): kotlin.Int +public external fun f(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.String = ...): kotlin.Unit +public external fun foo(): kotlin.Int +public external fun g(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.String = ...): kotlin.Unit + +public external final class C { + public constructor C() + public final 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 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.kt index 2964529646b..ac289e09442 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.kt @@ -2,36 +2,36 @@ external class A { @nativeGetter - fun get(a: String): Any? = null + fun get(a: String): Any? = noImpl @nativeGetter - fun take(a: Number): String? = null + fun take(a: Number): String? = noImpl @nativeGetter - fun foo(a: Double): String? = null + fun foo(a: Double): String? = noImpl companion object { @nativeGetter - fun get(a: String): Any? = null + fun get(a: String): Any? = noImpl @nativeGetter - fun take(a: Number): String? = null + fun take(a: Number): String? = noImpl @nativeGetter - fun foo(a: Double): String? = null + fun foo(a: Double): String? = noImpl } } external class B { @nativeGetter - val foo = 0 + val foo: Int = noImpl @nativeGetter object Obj1 {} companion object { @nativeGetter - val foo = 0 + val foo: Int = noImpl @nativeGetter object Obj2 {} @@ -40,18 +40,18 @@ external class B { external class C { @nativeGetter - fun get(): Any? = null + fun get(): Any? = noImpl @nativeGetter - fun get(a: A): Any? = null + fun get(a: A): Any? = noImpl @nativeGetter - fun foo(a: Int) {} + fun foo(a: Int) { noImpl } @nativeGetter - fun bar(a: String): Int = 0 + fun bar(a: String): Int = noImpl @nativeGetter - fun baz(a: String = "foo"): Int? = 0 + fun baz(a: String = noImpl): Int? = noImpl } \ 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 1a14273103c..ae27662ce7d 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.txt @@ -22,14 +22,14 @@ public external final class A { public external final class B { public constructor B() - @kotlin.js.nativeGetter public final val foo: kotlin.Int = 0 + @kotlin.js.nativeGetter public final val foo: 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 companion object Companion { private constructor Companion() - @kotlin.js.nativeGetter public final val foo: kotlin.Int = 0 + @kotlin.js.nativeGetter public final val foo: 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/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.kt index ce813f9e666..cd96b1cdcf3 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.kt @@ -4,36 +4,36 @@ external class A { class B { class A { @nativeGetter - fun get(a: String): Any? = null + fun get(a: String): Any? = noImpl @nativeGetter - fun take(a: Number): String? = null + fun take(a: Number): String? = noImpl @nativeGetter - fun foo(a: Double): String? = null + fun foo(a: Double): String? = noImpl companion object { @nativeGetter - fun get(a: String): Any? = null + fun get(a: String): Any? = noImpl @nativeGetter - fun take(a: Number): String? = null + fun take(a: Number): String? = noImpl @nativeGetter - fun foo(a: Double): String? = null + fun foo(a: Double): String? = noImpl } } class B { @nativeGetter - val foo = 0 + val foo: Int = noImpl @nativeGetter object Obj1 {} companion object { @nativeGetter - val foo = 0 + val foo: Int = noImpl @nativeGetter object Obj2 {} @@ -42,53 +42,36 @@ external class A { class C { @nativeGetter - fun get(): Any? = null + fun get(): Any? = noImpl @nativeGetter - fun get(a: A): Any? = null + fun get(a: A): Any? = noImpl @nativeGetter - fun foo(a: Int) {} + fun foo(a: Int) { noImpl } @nativeGetter - fun bar(a: String): Int = 0 + fun bar(a: String): Int = noImpl @nativeGetter - fun baz(a: Number = 1.1): Int? = 0 + fun baz(a: Number = noImpl): Int? = noImpl } object obj { @nativeGetter - fun get(): Any? = null + fun get(): Any? = noImpl @nativeGetter - fun get(a: A): Any? = null + fun get(a: A): Any? = noImpl @nativeGetter - fun foo(a: Int) {} + fun foo(a: Int) { noImpl } @nativeGetter - fun bar(a: String): Int = 0 + fun bar(a: String): Int = noImpl @nativeGetter - fun baz(a: String = "foo"): Int? = 0 - } - - val anonymous = object { - @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 + fun baz(a: String = noImpl): Int? = noImpl } } } \ 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 7493ed41496..4e233004150 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.txt @@ -8,7 +8,6 @@ public external final class A { public final class B { public constructor B() - public final val anonymous: kotlin.Any 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 @@ -35,14 +34,14 @@ public external final class A { public final class B { public constructor B() - @kotlin.js.nativeGetter public final val foo: kotlin.Int = 0 + @kotlin.js.nativeGetter public final val foo: 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 companion object Companion { private constructor Companion() - @kotlin.js.nativeGetter public final val foo: kotlin.Int = 0 + @kotlin.js.nativeGetter public final val foo: 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/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.kt index 4b352e132b9..bc4cd9e9f49 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.kt @@ -2,26 +2,26 @@ external class A { @nativeInvoke - fun foo() {} + fun foo() {noImpl} @nativeInvoke - fun invoke(a: String): Int = 0 + fun invoke(a: String): Int = noImpl @nativeInvoke - val foo = 0 + val foo: Int = noImpl @nativeInvoke object Obj1 {} companion object { @nativeInvoke - fun foo() {} + fun foo() { noImpl } @nativeInvoke - fun invoke(a: String): Int = 0 + fun invoke(a: String): Int = noImpl @nativeInvoke - val foo = 0 + val foo: Int = noImpl @nativeInvoke object Obj2 {} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.txt index 7385d06aeff..588cf2cb830 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.txt @@ -2,7 +2,7 @@ package public external final class A { public constructor A() - @kotlin.js.nativeInvoke public final val foo: kotlin.Int = 0 + @kotlin.js.nativeInvoke public final val foo: kotlin.Int public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean @kotlin.js.nativeInvoke public final fun foo(): kotlin.Unit public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int @@ -11,7 +11,7 @@ public external final class A { public companion object Companion { private constructor Companion() - @kotlin.js.nativeInvoke public final val foo: kotlin.Int = 0 + @kotlin.js.nativeInvoke public final val foo: kotlin.Int public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean @kotlin.js.nativeInvoke public final fun foo(): kotlin.Unit public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.kt index 057924be321..f5842bb1404 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.kt @@ -4,34 +4,26 @@ external class A { class B { class C { @nativeInvoke - fun foo() {} + fun foo() { noImpl } @nativeInvoke - fun invoke(a: String): Int = 0 + fun invoke(a: String): Int = noImpl } object obj { @nativeInvoke - fun foo() {} + fun foo() { noImpl } @nativeInvoke - fun invoke(a: String): Int = 0 + fun invoke(a: String): Int = noImpl } companion object { @nativeInvoke - fun foo() {} + fun foo() { noImpl } @nativeInvoke - fun invoke(a: String): Int = 0 - } - - val anonymous = object { - @nativeInvoke - fun foo() {} - - @nativeInvoke - fun invoke(a: String): Int = 0 + fun invoke(a: String): Int = noImpl } } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.txt index b665846638f..85bc40c3c14 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.txt @@ -8,7 +8,6 @@ public external final class A { public final class B { public constructor B() - public final val anonymous: kotlin.Any 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/nativeSetter/onNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.kt index 42aca651511..b6d4ef55fc3 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.kt @@ -2,48 +2,48 @@ external class A { @nativeSetter - fun set(a: String, v: Any?): Any? = null + fun set(a: String, v: Any?): Any? = noImpl @nativeSetter - fun put(a: Number, v: String) {} + fun put(a: Number, v: String) { noImpl } @nativeSetter - fun foo(a: Int, v: String) {} + fun foo(a: Int, v: String) { noImpl } @nativeSetter - fun set4(a: Double, v: String): Any = 1 + fun set4(a: Double, v: String): Any = noImpl @nativeSetter - fun set5(a: Double, v: String): CharSequence = "OK" + fun set5(a: Double, v: String): CharSequence = noImpl companion object { @nativeSetter - fun set(a: String, v: Any?): Any? = null + fun set(a: String, v: Any?): Any? = noImpl @nativeSetter - fun put(a: Number, v: String) {} + fun put(a: Number, v: String) { noImpl } @nativeSetter - fun foo(a: Int, v: String) {} + fun foo(a: Int, v: String) { noImpl } @nativeSetter - fun set4(a: Double, v: String): Any = 1 + fun set4(a: Double, v: String): Any = noImpl @nativeSetter - fun set5(a: Double, v: String): CharSequence = "OK" + fun set5(a: Double, v: String): CharSequence = noImpl } } external class B { @nativeSetter - val foo = 0 + val foo: Int = noImpl @nativeSetter object Obj1 {} companion object { @nativeSetter - val foo = 0 + val foo: Int = noImpl @nativeSetter object Obj2 {} @@ -52,20 +52,20 @@ external class B { external class C { @nativeSetter - fun set6(a: Double, v: String): Number = 1 + fun set6(a: Double, v: String): Number = noImpl @nativeSetter - fun set(): Any? = null + fun set(): Any? = noImpl @nativeSetter - fun set(a: A): Any? = null + fun set(a: A): Any? = noImpl @nativeSetter - fun set(a: String, v: Any, v2: Any) {} + fun set(a: String, v: Any, v2: Any) { noImpl } @nativeSetter - fun set(a: A, v: Any?) {} + fun set(a: A, v: Any?) { noImpl } @nativeSetter - fun foo(a: Number, v: String = "aa") = "OK" + fun foo(a: Number, v: String = noImpl): String = noImpl } \ 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 02255dee7c8..8afc5f011d8 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.txt @@ -26,14 +26,14 @@ public external final class A { public external final class B { public constructor B() - @kotlin.js.nativeSetter public final val foo: kotlin.Int = 0 + @kotlin.js.nativeSetter public final val foo: 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 companion object Companion { private constructor Companion() - @kotlin.js.nativeSetter public final val foo: kotlin.Int = 0 + @kotlin.js.nativeSetter public final val foo: 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/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.kt index 46c944bd52b..bc4f69a6500 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.kt @@ -4,48 +4,48 @@ external class A { class B { class A { @nativeSetter - fun set(a: String, v: Any?): Any? = null + fun set(a: String, v: Any?): Any? = noImpl @nativeSetter - fun put(a: Number, v: String) {} + fun put(a: Number, v: String) { noImpl } @nativeSetter - fun foo(a: Int, v: String) {} + fun foo(a: Int, v: String) { noImpl } @nativeSetter - fun set4(a: Double, v: String): Any = 1 + fun set4(a: Double, v: String): Any = noImpl @nativeSetter - fun set5(a: Double, v: String): CharSequence = "OK" + fun set5(a: Double, v: String): CharSequence = noImpl companion object { @nativeSetter - fun set(a: String, v: Any?): Any? = null + fun set(a: String, v: Any?): Any? = noImpl @nativeSetter - fun put(a: Number, v: String) {} + fun put(a: Number, v: String) { noImpl } @nativeSetter - fun foo(a: Int, v: String) {} + fun foo(a: Int, v: String) { noImpl } @nativeSetter - fun set4(a: Double, v: String): Any = 1 + fun set4(a: Double, v: String): Any = noImpl @nativeSetter - fun set5(a: Double, v: String): CharSequence = "OK" + fun set5(a: Double, v: String): CharSequence = noImpl } } class B { @nativeSetter - val foo = 0 + val foo: Int = noImpl @nativeSetter object Obj1 {} companion object { @nativeSetter - val foo = 0 + val foo: Int = noImpl @nativeSetter object Obj2 {} @@ -54,56 +54,39 @@ external class A { class C { @nativeSetter - fun set6(a: Double, v: String): Number = 1 + fun set6(a: Double, v: String): Number = noImpl @nativeSetter - fun set(): Any? = null + fun set(): Any? = noImpl @nativeSetter - fun set(a: A): Any? = null + fun set(a: A): Any? = noImpl @nativeSetter - fun set(a: String, v: Any, v2: Any) {} + fun set(a: String, v: Any, v2: Any) { noImpl } @nativeSetter - fun set(a: A, v: Any?) {} + fun set(a: A, v: Any?) { noImpl } @nativeSetter - fun foo(a: Double = 0.0, v: String = "str") = "OK" + fun foo(a: Double = noImpl, v: String = noImpl): String = noImpl } object obj { @nativeSetter - fun set(): Any? = null + fun set(): Any? = noImpl @nativeSetter - fun set(a: A): Any? = null + fun set(a: A): Any? = noImpl @nativeSetter - fun set(a: String, v: Any, v2: Any) {} + fun set(a: String, v: Any, v2: Any) { noImpl } @nativeSetter - fun set(a: A, v: Any?) {} + fun set(a: A, v: Any?) { noImpl } @nativeSetter - fun foo(a: Int, v: String = "str") = "OK" - } - - val anonymous = object { - @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" + fun foo(a: Int, v: String = noImpl): String = noImpl } } } \ 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 939702c6e39..e8a308fa324 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.txt @@ -8,7 +8,6 @@ public external final class A { public final class B { public constructor B() - public final val anonymous: kotlin.Any 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 @@ -39,14 +38,14 @@ public external final class A { public final class B { public constructor B() - @kotlin.js.nativeSetter public final val foo: kotlin.Int = 0 + @kotlin.js.nativeSetter public final val foo: 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 companion object Companion { private constructor Companion() - @kotlin.js.nativeSetter public final val foo: kotlin.Int = 0 + @kotlin.js.nativeSetter public final val foo: 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/testData/diagnostics/testsWithJsStdLib/native/nested.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.kt index 7bf2a09e1ca..6b45f74d50b 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.kt @@ -24,11 +24,11 @@ external class TopLevelNative { class B - fun foo() = 23 + fun foo(): Int = noImpl external fun bar(): Int - val x = "a" + val x: String = noImpl external val y: String } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.txt index 73dc68c4d06..bdd86daba13 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.txt @@ -38,7 +38,7 @@ public final class TopLevel { public external final class TopLevelNative { public constructor TopLevelNative() - public final val x: kotlin.String = "a" + public final val x: kotlin.String public external final val y: kotlin.String public final external fun bar(): kotlin.Int public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.kt index 40ac0dc5868..41442764118 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.kt @@ -5,7 +5,7 @@ external val baz: Int external val boo: Int = noImpl external fun foo() -external fun bar() {} +external fun bar() { noImpl } external interface T { val baz: Int @@ -27,7 +27,7 @@ external class C { val boo: Int = noImpl fun foo() - fun bar() {} + fun bar() { noImpl } companion object { val baz: Int diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/nativeInvoke.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/nativeInvoke.kt index 53784154f42..34cbfc0574c 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/nativeInvoke.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/nativeInvoke.kt @@ -9,5 +9,5 @@ external object O { @nativeInvoke fun foo() @nativeInvoke - fun bar() {} + fun bar() { noImpl } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/overrideOptionalParam.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/overrideOptionalParam.kt index 9a8ccb00f13..1bdb2180a1b 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/overrideOptionalParam.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/overrideOptionalParam.kt @@ -7,7 +7,7 @@ class B : A() { } external class C : A() { - override fun f(x: Int) {} + override fun f(x: Int) } @@ -24,7 +24,7 @@ open external class D { } class E : D() { - override fun f(x: Int) {} + override fun f(x: Int) { } } class F : D(), I { @@ -32,7 +32,7 @@ class F : D(), I { } external class G : D(), I { - override fun f(x: Int) {} + override fun f(x: Int) } open class X { diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/native.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/native.kt index c9dcb24ff9f..3da0bdaf335 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/native.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/native.kt @@ -1,12 +1,12 @@ external fun foo(a: String): Int = noImpl external class Bar(b: Int, c: Char) { - fun baz(d: Int) {} + fun baz(d: Int) { noImpl } } external object Obj { - fun test1(e: String) {} + fun test1(e: String) { noImpl } object Nested { - fun test2(g: Int) {} + fun test2(g: Int) { noImpl } } } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeInvoke.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeInvoke.kt index 07e52928695..39789ab212f 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeInvoke.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeInvoke.kt @@ -4,15 +4,15 @@ fun Int.foo(a: String): Int = noImpl external class Bar(b: Int, c: Char) { @nativeInvoke - fun baz(d: Int) {} + fun baz(d: Int) { noImpl } } external object Obj { @nativeInvoke - fun test1(e: String) {} + fun test1(e: String) { noImpl } object Nested { @nativeInvoke - fun test2(g: Int) {} + fun test2(g: Int) { noImpl } } } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeSetter.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeSetter.kt index ed41b75210d..2316550723e 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeSetter.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeSetter.kt @@ -4,15 +4,15 @@ fun Int.foo(a: String, v: Int): Int = noImpl external class Bar(b: Int, c: Char) { @nativeSetter - fun baz(d: Int, v: Int) {} + fun baz(d: Int, v: Int) { noImpl } } external object Obj { @nativeSetter - fun test1(e: String, v: Any) {} + fun test1(e: String, v: Any) { noImpl } object Nested { @nativeSetter - fun test2(g: Int, v: Any) {} + fun test2(g: Int, v: Any) { noImpl } } } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java index f4bdcb8f558..d22c9ee826a 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java @@ -569,6 +569,12 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithJsStdLib/native"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("body.kt") + public void testBody() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/body.kt"); + doTest(fileName); + } + @TestMetadata("extensionFunctionAndProperty.kt") public void testExtensionFunctionAndProperty() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.kt"); 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 3e6df6c18ce..dc094112395 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 @@ -75,6 +75,7 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy { put(ErrorsJs.INLINE_EXTERNAL_DECLARATION, "Inline external declaration") put(ErrorsJs.NON_ABSTRACT_MEMBER_OF_EXTERNAL_INTERFACE, "Only nullable properties of external interfaces are allowed to be non-abstract") + put(ErrorsJs.WRONG_BODY_OF_EXTERNAL_DECLARATION, "Wrong body of external declaration. Must be either ' = noImpl' or { noImpl }") this } 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 57c60ceb739..5f395b01e4c 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 @@ -78,8 +78,9 @@ public interface ErrorsJs { ERROR, PositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT); DiagnosticFactory0 INLINE_EXTERNAL_DECLARATION = DiagnosticFactory0.create( ERROR, PositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT); - DiagnosticFactory0 NON_ABSTRACT_MEMBER_OF_EXTERNAL_INTERFACE = DiagnosticFactory0.create( + DiagnosticFactory0 NON_ABSTRACT_MEMBER_OF_EXTERNAL_INTERFACE = DiagnosticFactory0.create( ERROR, PositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT); + DiagnosticFactory0 WRONG_BODY_OF_EXTERNAL_DECLARATION = DiagnosticFactory0.create(ERROR); @SuppressWarnings("UnusedDeclaration") Object _initializer = new Object() { 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 be898e0eaab..6e9f0a407fe 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 @@ -22,18 +22,22 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticSink 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.name.FqNameUnsafe +import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.checkers.SimpleDeclarationChecker import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperInterfaces import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension +import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.utils.singletonOrEmptyList object JsExternalChecker : SimpleDeclarationChecker { + val NO_IMPL_PROPERTY_NAME = FqNameUnsafe("kotlin.js.noImpl") + override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, diagnosticHolder: DiagnosticSink, bindingContext: BindingContext) { if (!AnnotationsUtils.isNativeObject(descriptor)) return @@ -85,6 +89,34 @@ object JsExternalChecker : SimpleDeclarationChecker { ) { diagnosticHolder.report(ErrorsJs.NON_ABSTRACT_MEMBER_OF_EXTERNAL_INTERFACE.on(declaration)) } + + checkBody(declaration, diagnosticHolder, bindingContext) + } + + private fun checkBody(declaration: KtDeclaration, diagnosticHolder: DiagnosticSink, bindingContext: BindingContext) { + if (declaration is KtDeclarationWithBody && !declaration.hasValidExternalBody(bindingContext)) { + reportWrongBody(declaration.bodyExpression!!, diagnosticHolder, bindingContext) + } + else if (declaration is KtDeclarationWithInitializer && declaration.initializer?.isNoImplExpression(bindingContext) == false) { + reportWrongBody(declaration.initializer!!, diagnosticHolder, bindingContext) + } + if (declaration is KtCallableDeclaration) { + for (defaultValue in declaration.valueParameters.mapNotNull { it.defaultValue }) { + checkExternalExpression(defaultValue, diagnosticHolder, bindingContext) + } + } + } + + private fun checkExternalExpression(expression: KtExpression, diagnosticHolder: DiagnosticSink, bindingContext: BindingContext) { + if (!expression.isNoImplExpression(bindingContext)) { + reportWrongBody(expression, diagnosticHolder, bindingContext) + } + } + + private fun reportWrongBody(expression: KtExpression, diagnosticHolder: DiagnosticSink, bindingContext: BindingContext) { + if (bindingContext.diagnostics.forElement(expression).none { it.factory == ErrorsJs.WRONG_BODY_OF_EXTERNAL_DECLARATION }) { + diagnosticHolder.report(ErrorsJs.WRONG_BODY_OF_EXTERNAL_DECLARATION.on(expression)) + } } private fun isDirectlyExternal(declaration: KtDeclaration, descriptor: DeclarationDescriptor): Boolean {