JS: prohibit external functions and accessors with bodies other than noImpl. Prohibit to use anything except noImpl for default parameters initializers in external functions. See KT-13892

This commit is contained in:
Alexey Andreev
2016-12-19 19:35:16 +03:00
parent 55d4c0e439
commit 6ef4a3389e
28 changed files with 210 additions and 165 deletions
@@ -8,10 +8,10 @@ external class <!NESTED_JS_MODULE_PROHIBITED!>A<!>
external <!NESTED_JS_MODULE_PROHIBITED!>object B<!>
<!NESTED_JS_MODULE_PROHIBITED!>@JsModule("foo")
external fun foo()<!> = 23
external fun foo(): Int<!>
<!NESTED_JS_MODULE_PROHIBITED!>@JsModule("bar")
external val bar<!> = 42
external val bar: Int<!>
<!NESTED_JS_MODULE_PROHIBITED!>@JsNonModule
external val baz<!> = 99
external val baz: Int<!>
@@ -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 {
@@ -0,0 +1,30 @@
external fun foo(): Int = noImpl
external fun bar(): Unit {
noImpl
}
external fun baz(): Int = <!WRONG_BODY_OF_EXTERNAL_DECLARATION!>23<!>
external fun f(x: Int, y: String = noImpl): Unit
external fun g(x: Int, y: String = <!WRONG_BODY_OF_EXTERNAL_DECLARATION!>""<!>): Unit
external var a: Int
get() = noImpl
set(value) {
noImpl
}
external val b: Int
get() = <!WRONG_BODY_OF_EXTERNAL_DECLARATION!>23<!>
external val c: Int = noImpl
external val d: Int = <!WRONG_BODY_OF_EXTERNAL_DECLARATION!>23<!>
external class C {
fun foo(): Int = noImpl
fun bar(): Int = <!WRONG_BODY_OF_EXTERNAL_DECLARATION!>23<!>
}
@@ -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
}
@@ -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 {
<!WRONG_ANNOTATION_TARGET!>@nativeGetter<!>
val foo = 0
val foo: Int = noImpl
<!WRONG_ANNOTATION_TARGET!>@nativeGetter<!>
object Obj1 {}
companion object {
<!WRONG_ANNOTATION_TARGET!>@nativeGetter<!>
val foo = 0
val foo: Int = noImpl
<!WRONG_ANNOTATION_TARGET!>@nativeGetter<!>
object Obj2 {}
@@ -40,18 +40,18 @@ external class B {
external class C {
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeGetter
fun get(): Any?<!> = null
fun get(): Any?<!> = noImpl
@nativeGetter
fun get(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>): Any? = null
fun get(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>): Any? = noImpl
@nativeGetter
fun <!NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE!>foo<!>(a: Int) {}
fun <!NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE!>foo<!>(a: Int) { noImpl }
@nativeGetter
fun bar(a: String): <!NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE!>Int<!> = 0
fun bar(a: String): <!NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE!>Int<!> = noImpl
@nativeGetter
fun baz(<!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>a: String = "foo"<!>): Int? = 0
fun baz(<!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>a: String = noImpl<!>): Int? = noImpl
}
@@ -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
@@ -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 {
<!WRONG_ANNOTATION_TARGET!>@nativeGetter<!>
val foo = 0
val foo: Int = noImpl
<!WRONG_ANNOTATION_TARGET!>@nativeGetter<!>
object Obj1 {}
companion object {
<!WRONG_ANNOTATION_TARGET!>@nativeGetter<!>
val foo = 0
val foo: Int = noImpl
<!WRONG_ANNOTATION_TARGET!>@nativeGetter<!>
object Obj2 {}
@@ -42,53 +42,36 @@ external class A {
class C {
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeGetter
fun get(): Any?<!> = null
fun get(): Any?<!> = noImpl
@nativeGetter
fun get(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>): Any? = null
fun get(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>): Any? = noImpl
@nativeGetter
fun <!NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE!>foo<!>(a: Int) {}
fun <!NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE!>foo<!>(a: Int) { noImpl }
@nativeGetter
fun bar(a: String): <!NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE!>Int<!> = 0
fun bar(a: String): <!NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE!>Int<!> = noImpl
@nativeGetter
fun baz(<!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>a: Number = 1.1<!>): Int? = 0
fun baz(<!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>a: Number = noImpl<!>): Int? = noImpl
}
object obj {
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeGetter
fun get(): Any?<!> = null
fun get(): Any?<!> = noImpl
@nativeGetter
fun get(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>): Any? = null
fun get(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>): Any? = noImpl
@nativeGetter
fun <!NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE!>foo<!>(a: Int) {}
fun <!NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE!>foo<!>(a: Int) { noImpl }
@nativeGetter
fun bar(a: String): <!NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE!>Int<!> = 0
fun bar(a: String): <!NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE!>Int<!> = noImpl
@nativeGetter
fun baz(<!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>a: String = "foo"<!>): Int? = 0
}
val anonymous = object {
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeGetter
fun get(): Any?<!> = null
@nativeGetter
fun get(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>): Any? = null
@nativeGetter
fun <!NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE!>foo<!>(a: Int) {}
@nativeGetter
fun bar(a: String): <!NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE!>Int<!> = 0
@nativeGetter
fun baz(<!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>a: String = "foo"<!>): Int? = 0
fun baz(<!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>a: String = noImpl<!>): Int? = noImpl
}
}
}
@@ -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
@@ -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
<!WRONG_ANNOTATION_TARGET!>@nativeInvoke<!>
val foo = 0
val foo: Int = noImpl
<!WRONG_ANNOTATION_TARGET!>@nativeInvoke<!>
object Obj1 {}
companion object {
@nativeInvoke
fun foo() {}
fun foo() { noImpl }
@nativeInvoke
fun invoke(a: String): Int = 0
fun invoke(a: String): Int = noImpl
<!WRONG_ANNOTATION_TARGET!>@nativeInvoke<!>
val foo = 0
val foo: Int = noImpl
<!WRONG_ANNOTATION_TARGET!>@nativeInvoke<!>
object Obj2 {}
@@ -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
@@ -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
}
}
}
@@ -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
@@ -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 {
<!WRONG_ANNOTATION_TARGET!>@nativeSetter<!>
val foo = 0
val foo: Int = noImpl
<!WRONG_ANNOTATION_TARGET!>@nativeSetter<!>
object Obj1 {}
companion object {
<!WRONG_ANNOTATION_TARGET!>@nativeSetter<!>
val foo = 0
val foo: Int = noImpl
<!WRONG_ANNOTATION_TARGET!>@nativeSetter<!>
object Obj2 {}
@@ -52,20 +52,20 @@ external class B {
external class C {
@nativeSetter
fun set6(a: Double, v: String): <!NATIVE_SETTER_WRONG_RETURN_TYPE!>Number<!> = 1
fun set6(a: Double, v: String): <!NATIVE_SETTER_WRONG_RETURN_TYPE!>Number<!> = noImpl
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeSetter
fun set(): Any?<!> = null
fun set(): Any?<!> = noImpl
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeSetter
fun set(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>): Any?<!> = null
fun set(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>): Any?<!> = noImpl
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeSetter
fun set(a: String, v: Any, v2: Any)<!> {}
fun set(a: String, v: Any, v2: Any)<!> { noImpl }
@nativeSetter
fun set(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>, v: Any?) {}
fun set(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>, v: Any?) { noImpl }
@nativeSetter
fun foo(a: Number, <!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>v: String = "aa"<!>) = "OK"
fun foo(a: Number, <!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>v: String = noImpl<!>): String = noImpl
}
@@ -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
@@ -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 {
<!WRONG_ANNOTATION_TARGET!>@nativeSetter<!>
val foo = 0
val foo: Int = noImpl
<!WRONG_ANNOTATION_TARGET!>@nativeSetter<!>
object Obj1 {}
companion object {
<!WRONG_ANNOTATION_TARGET!>@nativeSetter<!>
val foo = 0
val foo: Int = noImpl
<!WRONG_ANNOTATION_TARGET!>@nativeSetter<!>
object Obj2 {}
@@ -54,56 +54,39 @@ external class A {
class C {
@nativeSetter
fun set6(a: Double, v: String): <!NATIVE_SETTER_WRONG_RETURN_TYPE!>Number<!> = 1
fun set6(a: Double, v: String): <!NATIVE_SETTER_WRONG_RETURN_TYPE!>Number<!> = noImpl
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeSetter
fun set(): Any?<!> = null
fun set(): Any?<!> = noImpl
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeSetter
fun set(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>): Any?<!> = null
fun set(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>): Any?<!> = noImpl
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeSetter
fun set(a: String, v: Any, v2: Any)<!> {}
fun set(a: String, v: Any, v2: Any)<!> { noImpl }
@nativeSetter
fun set(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>, v: Any?) {}
fun set(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>, v: Any?) { noImpl }
@nativeSetter
fun foo(<!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>a: Double = 0.0<!>, <!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>v: String = "str"<!>) = "OK"
fun foo(<!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>a: Double = noImpl<!>, <!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>v: String = noImpl<!>): String = noImpl
}
object obj {
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeSetter
fun set(): Any?<!> = null
fun set(): Any?<!> = noImpl
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeSetter
fun set(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>): Any?<!> = null
fun set(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>): Any?<!> = noImpl
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeSetter
fun set(a: String, v: Any, v2: Any)<!> {}
fun set(a: String, v: Any, v2: Any)<!> { noImpl }
@nativeSetter
fun set(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>, v: Any?) {}
fun set(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>, v: Any?) { noImpl }
@nativeSetter
fun foo(a: Int, <!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>v: String = "str"<!>) = "OK"
}
val anonymous = object {
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeSetter
fun set(): Any?<!> = null
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeSetter
fun set(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>): Any?<!> = null
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeSetter
fun set(a: String, v: Any, v2: Any)<!> {}
@nativeSetter
fun set(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: A<!>, v: Any?) {}
@nativeSetter
fun foo(<!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>a: Number = 0.0<!>, v: String) = "OK"
fun foo(a: Int, <!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>v: String = noImpl<!>): String = noImpl
}
}
}
@@ -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
@@ -24,11 +24,11 @@ external class TopLevelNative {
class B
fun foo() = 23
fun foo(): Int = noImpl
<!NESTED_EXTERNAL_DECLARATION!>external fun bar(): Int<!>
val x = "a"
val x: String = noImpl
<!NESTED_EXTERNAL_DECLARATION!>external val y: String<!>
}
@@ -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
@@ -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
@@ -9,5 +9,5 @@ external object O {
@nativeInvoke
fun foo()
@nativeInvoke
fun bar() {}
fun bar() { noImpl }
}
@@ -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 {
@@ -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 }
}
}
@@ -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 }
}
}
@@ -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 }
}
}
@@ -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");
@@ -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
}
@@ -78,8 +78,9 @@ public interface ErrorsJs {
ERROR, PositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT);
DiagnosticFactory0<KtDeclaration> INLINE_EXTERNAL_DECLARATION = DiagnosticFactory0.create(
ERROR, PositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT);
DiagnosticFactory0<KtDeclaration> NON_ABSTRACT_MEMBER_OF_EXTERNAL_INTERFACE = DiagnosticFactory0.create(
DiagnosticFactory0<KtExpression> NON_ABSTRACT_MEMBER_OF_EXTERNAL_INTERFACE = DiagnosticFactory0.create(
ERROR, PositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT);
DiagnosticFactory0<KtExpression> WRONG_BODY_OF_EXTERNAL_DECLARATION = DiagnosticFactory0.create(ERROR);
@SuppressWarnings("UnusedDeclaration")
Object _initializer = new Object() {
@@ -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 {