diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/classLiteral/arrays_after.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/classLiteral/arrays_after.fir.kt new file mode 100644 index 00000000000..6d0f0f0e2e3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/classLiteral/arrays_after.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: +BareArrayClassLiteral +ProhibitGenericArrayClassLiteral + +val a01 = Array::class +val a02 = Array<Array>::class +val a03 = Array::class +val a04 = Array?>::class +val a05 = Array::class +val a06 = kotlin.Array::class +val a07 = kotlin.Array::class diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/classLiteral/arrays_before.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/classLiteral/arrays_before.fir.kt new file mode 100644 index 00000000000..92620057103 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/classLiteral/arrays_before.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: -BareArrayClassLiteral -ProhibitGenericArrayClassLiteral + +val a01 = Array::class +val a02 = Array<Array>::class +val a03 = Array::class +val a04 = Array?>::class +val a05 = Array::class +val a06 = kotlin.Array::class +val a07 = kotlin.Array::class diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/allowedDynamicFunctionType.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/allowedDynamicFunctionType.fir.kt new file mode 100644 index 00000000000..5e098348d13 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/allowedDynamicFunctionType.fir.kt @@ -0,0 +1,17 @@ +// !MARK_DYNAMIC_CALLS + +fun withDynamicReceiver(d: dynamic.() -> Unit) {} + +fun test() = withDynamicReceiver { + foo + bar = 1 +} + +fun test2() = withDynamicReceiver(fun dynamic.() {}) + +val dynamicProperty: dynamic.() -> Unit = TODO() + +fun test(d: dynamic, dynamicParameter: dynamic.() -> Unit) { + d.dynamicProperty() + d.dynamicParameter() +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/assignment.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/assignment.kt index 127d0f14e96..4b072ffad04 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/assignment.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/assignment.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_VARIABLE // !CHECK_TYPE diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/block.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/block.fir.kt new file mode 100644 index 00000000000..8587d2f7080 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/block.fir.kt @@ -0,0 +1,13 @@ +// !MARK_DYNAMIC_CALLS + +fun test() { + dynamic { + foo() + bar.baz(0) + } +} + +fun dynamic(body: dynamic.() -> T): T { + val topLevel = null + return topLevel.body() +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/callableReferences.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/callableReferences.kt index 094c25bb1fe..a1429027cc7 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/callableReferences.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/callableReferences.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_EXPRESSION fun test() { @@ -6,4 +7,4 @@ fun test() { class dynamic { fun foo() {} -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/capturedDynamic.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/capturedDynamic.fir.kt new file mode 100644 index 00000000000..99811d81826 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/capturedDynamic.fir.kt @@ -0,0 +1,27 @@ +// SKIP_TXT + +fun case_1(vararg args: dynamic) { + (")!>listOf(null) + args).toTypedArray() +} + +fun case_2(vararg args: dynamic) { + (")!>listOf() + args).toTypedArray() +} + +fun case_3(vararg args: dynamic) { + (")!>listOf(1) + args).toTypedArray() +} + +fun case_4(vararg args: dynamic) { + (")!>listOf() + args).toTypedArray() +} + +fun case_5(x: Any?) { + fun foo(x: List) = x + + foo(")!>listOf(null) + x as MutableList) +} + +fun case_6(x: Any?) { + (")!>listOf(null) + x as MutableList).toTypedArray() +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/capturedDynamicNI.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/capturedDynamicNI.fir.kt new file mode 100644 index 00000000000..99811d81826 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/capturedDynamicNI.fir.kt @@ -0,0 +1,27 @@ +// SKIP_TXT + +fun case_1(vararg args: dynamic) { + (")!>listOf(null) + args).toTypedArray() +} + +fun case_2(vararg args: dynamic) { + (")!>listOf() + args).toTypedArray() +} + +fun case_3(vararg args: dynamic) { + (")!>listOf(1) + args).toTypedArray() +} + +fun case_4(vararg args: dynamic) { + (")!>listOf() + args).toTypedArray() +} + +fun case_5(x: Any?) { + fun foo(x: List) = x + + foo(")!>listOf(null) + x as MutableList) +} + +fun case_6(x: Any?) { + (")!>listOf(null) + x as MutableList).toTypedArray() +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/classDelegateBy.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/classDelegateBy.fir.kt new file mode 100644 index 00000000000..edae7a13682 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/classDelegateBy.fir.kt @@ -0,0 +1,13 @@ +val x: dynamic = 23 + +interface I { + fun foo(): String +} + +class C : I by x + +object O : I by x + +fun box(): String { + return object : I by x {}.foo() +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/comparisonToNull.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/comparisonToNull.kt index 71751565a1f..8803d7b9ac3 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/comparisonToNull.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/comparisonToNull.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_VARIABLE fun test(d: dynamic) { @@ -7,4 +8,4 @@ fun test(d: dynamic) { d["foo"] != null d.foo == null d.foo != null -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/conditions.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/conditions.kt index ca5eb0f9b09..87234c5833a 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/conditions.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/conditions.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL fun test(d: dynamic, b: Boolean?) { if (d) {} while (d) {} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/conventions.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/conventions.fir.kt new file mode 100644 index 00000000000..31f72feee7f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/conventions.fir.kt @@ -0,0 +1,82 @@ +// !DIAGNOSTICS: -NON_TOPLEVEL_CLASS_DECLARATION +// !MARK_DYNAMIC_CALLS + +fun test(d: dynamic) { + +d + -d + ! d + + + d + d + d + 1 + "" + d + + d - d + d * d + d / d + d % d + + d and d + + d[1] + + d[1] = 2 + + d[1]++ + ++d[1] + + d[1]-- + --d[1] + + d() + d(1) + d(name = 1) + d {} + + class C { + val plus: dynamic = null + } + + C() + 5 // todo should be marked as DEBUG_INFO_DYNAMIC + C().plus(5) + + d == d + d != d + + d === d + d !== d + + d < d + d <= d + d >= d + d > d + + for (i in d) { + i.foo() + } + + var dVar = d + dVar++ + ++dVar + + dVar-- + --dVar + + dVar += 1 + dVar -= 1 + dVar *= 1 + dVar /= 1 + dVar %= 1 + + d += 1 + d -= 1 + d *= 1 + d /= 1 + d %= 1 + + d[1] += 1 + d[1] -= 1 + d[1] *= 1 + d[1] /= 1 + d[1] %= 1 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/destructuring.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/destructuring.fir.kt new file mode 100644 index 00000000000..0378cfa6e77 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/destructuring.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo() { + for ((x, y) in A()) { + println(x + y) + } + + bar { (x, y) -> + println(x + y) + } + + val x: dynamic = Any() + + val (y, z) = x + println(y + z) +} + +class A { + operator fun iterator(): Iterator = TODO("") +} + +fun bar(f: (dynamic) -> Unit): Unit = TODO("") diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCalls.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCalls.kt index 39e8566d926..57602890293 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCalls.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCalls.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL fun test(d: dynamic) { val v1 = d.foo() v1.isDynamic() // to check that anything is resolvable @@ -15,4 +16,4 @@ fun test(d: dynamic) { v5.isDynamic() // to check that anything is resolvable d.foo = 1 -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.fir.kt new file mode 100644 index 00000000000..dcf1109eb91 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.fir.kt @@ -0,0 +1,34 @@ +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER +// !CHECK_TYPE + +fun test(d: dynamic) { + d.foo {} + + d.foo { it } + + d.foo { x -> } + + d.foo { x: Int -> "" } + + d.foo { x, y -> "" } + + d.foo { x: String, y: Int -> "" } + + d.foo { x, y: Int -> "" } + + d.foo({}) + + d.foo({ x -> }) + + d.foo(checkSubtype<(Int) -> Unit>({ x -> })) + + d.foo(label@ { x -> }) + + d.foo(label@ ({ x, y -> })) + + d.foo((label@ ({ x, y: Int -> }))) + + d.foo(({ x -> })) + + d.foo((({ x -> }))) +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCastTarget.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCastTarget.fir.kt new file mode 100644 index 00000000000..60eea0bca92 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCastTarget.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -REDUNDANT_NULLABLE + +fun test(d: Any, dl: Collection) { + d as dynamic + d as dynamic? + + d as? dynamic + d as? dynamic? + + d is dynamic + d is dynamic? + + d !is dynamic + d !is dynamic? + + when (d) { + is dynamic -> {} + is dynamic? -> {} + !is dynamic -> {} + !is dynamic? -> {} + } + + dl as List + dl is List + + when (dl) { + is List -> {} + } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicExtension.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicExtension.fir.kt new file mode 100644 index 00000000000..38fba4f4fc3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicExtension.fir.kt @@ -0,0 +1,28 @@ +// !MARK_DYNAMIC_CALLS + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@kotlin.internal.DynamicExtension +fun dynamic.onDynamicFun() = 1 + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@kotlin.internal.DynamicExtension +var dynamic.onDynamicProperty + get() = "" + set(value) {} + + +fun test(d: dynamic, a: Any?) { + eatT(d.onDynamicFun()) + eatT(d.onDynamicProperty) + d.onDynamicProperty = "" + eatT>(d.iterator()) + + for (item in d) { + println(item) + } + + a.onDynamicFun() + a.onDynamicProperty +} + +fun eatT(t: T) {} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicSafeCalls.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicSafeCalls.kt index 33c373de5b6..41ef58c9d73 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicSafeCalls.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicSafeCalls.kt @@ -1,7 +1,8 @@ +// FIR_IDENTICAL fun test(d: dynamic) { val v1 = d?.foo() v1.isDynamic() // to check that anything is resolvable val v2 = d!!.foo(1) v2.isDynamic() // to check that anything is resolvable -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicVsGeneric.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicVsGeneric.fir.kt new file mode 100644 index 00000000000..3fa50ae9805 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicVsGeneric.fir.kt @@ -0,0 +1,9 @@ +object X1 +object X2 + +class Inv + +fun dynamic.foo() = X1 +fun Inv.foo() = X2 + +fun test(): X2 = Inv().foo() diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/extensionVals.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/extensionVals.fir.kt new file mode 100644 index 00000000000..fd099b12a3a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/extensionVals.fir.kt @@ -0,0 +1,58 @@ +// !DIAGNOSTICS:-USELESS_CAST +// !MARK_DYNAMIC_CALLS + +fun test(d: dynamic) { + d.onAnyVal + d.onAnyVal = 1 + + d?.onAnyVal + d?.onAnyVal = 1 + + run { + d!!.onAnyVal + } + run { + d!!.onAnyVal = 1 + } + + d.onNullableAnyVal = 1 + + d.onStringVal = 1 + + d.onDynamicVal = 1 + + (d as String).onStringVal + (d as Any).onAnyVal + (d as Any?).onNullableAnyVal + (d as Any).onDynamicVal +} + +fun testReassignmentWithSafeCall(d: dynamic) { + d?.onDynamicVal = 1 +} + +fun testReassignmentWithStaticCalls(d: dynamic) { + (d as String).onStringVal = 1 + (d as Any).onAnyVal = 1 + (d as Any?).onNullableAnyVal = 1 + (d as Any).onDynamicVal = 1 +} + +val Any.onAnyVal: Int get() = 1 +val Any?.onNullableAnyVal: Int get() = 1 +val String.onStringVal: Int get() = 1 +val dynamic.onDynamicVal: Int get() = 1 + +class C { + fun test(d: dynamic) { + d.memberVal + d.memberVal = 1 + + d.memberExtensionVal + d.memberExtensionVal = 1 + } + + val memberVal = 1 + val Any.memberExtensionVal: Int + get() = 1 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/extensionVars.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/extensionVars.fir.kt new file mode 100644 index 00000000000..342b19ac5f8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/extensionVars.fir.kt @@ -0,0 +1,67 @@ +// !MARK_DYNAMIC_CALLS +// !DIAGNOSTICS:-USELESS_CAST + +fun test(d: dynamic) { + d.onAnyVar + d.onAnyVar = 1 + + d?.onAnyVar + d?.onAnyVar = 1 + + run { + d!!.onAnyVar + + } + run { + d!!.onAnyVar = 1 + } + + d.onNullableAnyVar = 1 + + d.onStringVar = 1 + + d.onDynamicVar = 1 + + d?.onDynamicVar = 1 + + (d as String).onStringVar + (d as Any).onAnyVar + (d as Any?).onNullableAnyVar + (d as Any).onDynamicVar + + (d as String).onStringVar = 1 + (d as Any).onAnyVar = 1 + (d as Any?).onNullableAnyVar = 1 + (d as Any).onDynamicVar = 1 +} + +var Any.onAnyVar: Int + get() = 1 + set(v) {} + +var Any?.onNullableAnyVar: Int + get() = 1 + set(v) {} + +var String.onStringVar: Int + get() = 1 + set(v) {} + +var dynamic.onDynamicVar: Int + get() = 1 + set(v) {} + +class C { + fun test(d: dynamic) { + d.memberVar + d.memberExtensionVar + + d.memberVar = 1 + d.memberExtensionVar = 1 + } + + var memberVar = 1 + var Any.memberExtensionVar: Int + get() = 1 + set(v) {} +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/extensions.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/extensions.fir.kt new file mode 100644 index 00000000000..d79d3a233f7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/extensions.fir.kt @@ -0,0 +1,38 @@ +// !DIAGNOSTICS:-USELESS_CAST +// !MARK_DYNAMIC_CALLS + +fun test(d: dynamic) { + d.onAny() + d?.onAny() + run { + d!!.onAny() + } + + d.onAny(1) + + d.onNullableAny() + d.onString() + + d.onDynamic() + d?.onDynamic() + + (d as String).onString() + (d as Any).onAny() + (d as Any?).onNullableAny() + (d as Any).onDynamic() +} + +fun Any.onAny() {} +fun Any?.onNullableAny() {} +fun String.onString() {} +fun dynamic.onDynamic() {} + +class C { + fun test(d: dynamic) { + d.member() + d.memberExtension() + } + + fun member() {} + fun Any.memberExtension() {} +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/extensionsToDynamic.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/extensionsToDynamic.fir.kt new file mode 100644 index 00000000000..f6514f2e852 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/extensionsToDynamic.fir.kt @@ -0,0 +1,58 @@ +// !MARK_DYNAMIC_CALLS + +fun test(d: dynamic) { + d.onDynamic() + d.onNullableDynamic() + + d.valOnDynamic + d.valOnDynamic = 1 + + d.varOnDynamic + d.varOnDynamic = 1 +} + +fun dynamic.extTest() { + onDynamic() + onNullableDynamic() + + valOnDynamic + valOnDynamic = 1 + + varOnDynamic + varOnDynamic = 1 + + this.onDynamic() + this.onNullableDynamic() + + this.valOnDynamic + this.valOnDynamic = 1 + + this.varOnDynamic + this.varOnDynamic = 1 + +} + +fun dynamic.onDynamic() {} +fun dynamic?.onNullableDynamic() {} + +val dynamic.valOnDynamic: Int get() = 1 + +var dynamic.varOnDynamic: Int + get() = 1 + set(v) {} + + +class ForMemberExtensions { + fun test(d: dynamic) { + d.memberExtensionVar + d.memberExtensionVar = 1 + + d.memberExtensionVal + d.memberExtensionVal = 1 + } + + val dynamic.memberExtensionVal: Int get() = 1 + var dynamic.memberExtensionVar: Int + get() = 1 + set(v) {} +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/implicitDynamicReceiver.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/implicitDynamicReceiver.fir.kt new file mode 100644 index 00000000000..af01eb120a8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/implicitDynamicReceiver.fir.kt @@ -0,0 +1,18 @@ +fun dynamic.test() { + val v1 = foo() + v1.isDynamic() // to check that anything is resolvable + + val v2 = foo(1) + v2.isDynamic() // to check that anything is resolvable + + val v3 = foo(1, "") + v3.isDynamic() // to check that anything is resolvable + + val v4 = foo() + v4.isDynamic() // to check that anything is resolvable + + val v5 = foo + v5.isDynamic() // to check that anything is resolvable + + foo = 1 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/inExpression.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/inExpression.fir.kt new file mode 100644 index 00000000000..e0206322b08 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/inExpression.fir.kt @@ -0,0 +1,12 @@ +fun foo() { + val a: dynamic = Any() + println(a in setOf(1, 2)) + println(1 in a) + println(1 !in a) + when (2) { + in a -> println("ok") + } + when (3) { + !in a -> println("ok") + } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/indexedAccess.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/indexedAccess.fir.kt new file mode 100644 index 00000000000..6f38b4a8006 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/indexedAccess.fir.kt @@ -0,0 +1,8 @@ +fun foo() { + val a: dynamic = Any() + println(a[0]) + println(a[0, 1]) + + a[0] = 23 + a[0, 1] = 42 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/inference.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/inference.fir.kt new file mode 100644 index 00000000000..e951c3a91d4 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/inference.fir.kt @@ -0,0 +1,26 @@ +// !MARK_DYNAMIC_CALLS +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(t1: T, t2: T): T = t1 + +interface Tr +class C: Tr +fun foo1(t1: T, t2: T): T = t1 + +fun test(d: dynamic, b: Boolean, n: String?) { + foo(d, "").foo() + foo1(d, C()).foo() + + val fromIf = if (b) d else "" + fromIf.doo() + + val fromElvis = n ?: d + fromElvis.doo() +} + +class In(t: T) +fun contra(a: In, b: In): T = null!! + +fun testContra(d: dynamic) { + contra(In(d), In("")).get(0) // not a dynamic call +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/membersOfAny.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/membersOfAny.kt index 97fb9732d26..19139463efe 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/membersOfAny.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/membersOfAny.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !MARK_DYNAMIC_CALLS fun test(d: dynamic) { diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/namedArguments.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/namedArguments.fir.kt new file mode 100644 index 00000000000..59eafd7b24f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/namedArguments.fir.kt @@ -0,0 +1,7 @@ +fun test(d: dynamic) { + d.foo(name = "name") + + d.foo(1, name = "name") + + d.foo(1, duplicate = "", duplicate = "") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/noUnsupportedInLocals.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/noUnsupportedInLocals.kt index e5494ad6293..3b04be33ecb 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/noUnsupportedInLocals.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/noUnsupportedInLocals.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -NON_TOPLEVEL_CLASS_DECLARATION val foo: dynamic = 1 @@ -6,4 +7,4 @@ fun bar() { class C { val foo: dynamic = 1 } -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/nullable.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/nullable.fir.kt new file mode 100644 index 00000000000..ef8d89f671c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/nullable.fir.kt @@ -0,0 +1,16 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(dn: dynamic?, d: dynamic, dnn: dynamic??) { + val a1 = dn.foo() + a1.isDynamic() + + val a2 = dn?.foo() + a2.isDynamic() + + val a3 = dn!!.foo() + a3.isDynamic() + + d.foo() + d?.foo() + d!!.foo() +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/overloading.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/overloading.fir.kt new file mode 100644 index 00000000000..747a260f686 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/overloading.fir.kt @@ -0,0 +1,23 @@ +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun dyn(d: dynamic) {} + +fun foo(d: dynamic): String = "" +fun foo(d: Int): Int = 1 + +fun nothing(d: dynamic): Int = 1 +fun nothing(d: Nothing): String = "" + +fun test(d: dynamic) { + dyn(1) + dyn("") + + foo(1).checkType { _() } + foo("").checkType { _() } + + // Checking specificity of `dynamic` vs `Nothing` + nothing(d).checkType { _() } + nothing("").checkType { _() } + @Suppress("UNREACHABLE_CODE") nothing(null!!).checkType { _() } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/overloadingAmbiguity.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/overloadingAmbiguity.fir.kt new file mode 100644 index 00000000000..121daac5ea4 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/overloadingAmbiguity.fir.kt @@ -0,0 +1,11 @@ +// !MARK_DYNAMIC_CALLS +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun dynamic.foo(s: String, a: Any) {} +fun dynamic.foo(s: Any, a: String) {} + +fun test(d: dynamic) { + d.foo(1, "") + d.foo("", "") + d.foo(1, 1) +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/overrides.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/overrides.kt index 53a745600b0..3cb69849ce8 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/overrides.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/overrides.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL interface P interface R diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/propertyDelegateBy.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/propertyDelegateBy.fir.kt new file mode 100644 index 00000000000..6f5a5f5e4a4 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/propertyDelegateBy.fir.kt @@ -0,0 +1,27 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +external val x: dynamic + +var y: Any? by x + +fun foo() { + val a: Any by x +} + +class C { + val a: dynamic by x +} + +class A { + operator fun provideDelegate(host: Any?, p: Any): dynamic = TODO("") +} + +val z: Any? by A() + +class DynamicHandler { + operator fun getValue(thisRef: Any?, property: kotlin.reflect.KProperty<*>): dynamic = 23 +} + +class B { + val x: dynamic by DynamicHandler() +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/protected.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/protected.kt index 2192edd2531..58083be4318 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/protected.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/protected.kt @@ -1,5 +1,6 @@ +// FIR_IDENTICAL open class Foo { open protected fun bar(a: dynamic){ a.something } -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/rangeExpression.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/rangeExpression.fir.kt new file mode 100644 index 00000000000..6829a4d8806 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/rangeExpression.fir.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo() { + val a: dynamic = Any() + val b: dynamic = Any() + val c = C() + println(a..b) + println(c..a) + println(a.rangeTo(b)) +} + +class C { + operator fun rangeTo(other: dynamic): ClosedRange = TODO("not implemented") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/rangeUntilExpression.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/rangeUntilExpression.fir.kt new file mode 100644 index 00000000000..bc704083732 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/rangeUntilExpression.fir.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !LANGUAGE: +RangeUntilOperator + +fun foo() { + val a: dynamic = Any() + val b: dynamic = Any() + val c = C() + println(a.. = TODO("not implemented") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/reified.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/reified.fir.kt new file mode 100644 index 00000000000..f42ace2fe27 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/reified.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -REIFIED_TYPE_PARAMETER_NO_INLINE + +fun foo(t: T) {} +class C(t: T) + +fun test(d: dynamic) { + foo(d) + foo(d) + + C(d) + C(d) +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/smartCast.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/smartCast.fir.kt new file mode 100644 index 00000000000..26a6e979430 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/smartCast.fir.kt @@ -0,0 +1,12 @@ +// !MARK_DYNAMIC_CALLS + +fun foo(d: dynamic) { + if (d is Foo) { + d.bar() // resolved statically + d.baz() + } +} + +class Foo { + fun bar() {} +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/spreadOperator.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/spreadOperator.fir.kt new file mode 100644 index 00000000000..54d5935745d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/spreadOperator.fir.kt @@ -0,0 +1,22 @@ +fun test(d: dynamic) { + val a = arrayOf(1, 2, 3) + + d.foo(*d) + d.foo(*a) + d.foo(1, "2", *a) + d.foo(1, *a) { } + d.foo(*a) { "" } + d.foo(*a, *a) + d.foo(*a, *a) { "" } + d.foo(*a, 1, { "" }, *a) + d.foo(*a, 1) + d.foo(*a, *a, { "" }) + + bar(d) + bar(d, d) + bar(*d) + bar(*d, *d) + bar(*d, 23, *d) +} + +fun bar(vararg x: Int): Unit = TODO("$x") diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/staticCallsInDynamicContext.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/staticCallsInDynamicContext.fir.kt new file mode 100644 index 00000000000..dce0478c1df --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/staticCallsInDynamicContext.fir.kt @@ -0,0 +1,74 @@ +// !MARK_DYNAMIC_CALLS +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun dynamic.test() { + foo() + ext() + + bar() + this.bar() + + baz = 2 + this.baz = 2 + + "".ext() + ext() + + "".extValFun() + extValFun() + + "".extVal + extVal + + baz.extExtVal() + extExtVal() + + ""() + this() + + C() + C() + +C() + + this + C() + + 0.missing() +} + +fun bar() {} +var baz = 1 + +fun Any.ext() {} + +val Any.extValFun: () -> Unit get() = null!! +val Any.extVal: () -> Unit get() = null!! + +val Any.extExtVal: Any.() -> Unit get() = null!! + +operator fun Any.invoke() {} + +operator fun Any.plus(a: Any) {} + +class C { + + operator fun String.invoke() {} + val foo: String.() -> Unit = null!! + + val s: String = "" + + val withInvoke = WithInvoke() + + fun dynamic.test() { + s() + this() + + s.foo() + this.foo() + + withInvoke() + this@C.withInvoke() + } +} + +class WithInvoke { + operator fun invoke() {} +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/staticExtensions.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/staticExtensions.fir.kt new file mode 100644 index 00000000000..5c078be7525 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/staticExtensions.fir.kt @@ -0,0 +1,12 @@ +// !MARK_DYNAMIC_CALLS + + +fun Any?.staticExtension() = 1 + +val Any?.staticProperty get() = 2 + +fun test(d: dynamic, staticParameter: Any?.() -> Unit) { + d.staticExtension() + d.staticProperty + d.staticParameter +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/substitution.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/substitution.fir.kt new file mode 100644 index 00000000000..4df336cca2c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/substitution.fir.kt @@ -0,0 +1,8 @@ +// !MARK_DYNAMIC_CALLS + +fun foo(d: dynamic) { + Foo(d).p.bar() + +} + +class Foo(val p: T) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/supertypesAndBounds.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/supertypesAndBounds.fir.kt new file mode 100644 index 00000000000..3d1ae597aa4 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/supertypesAndBounds.fir.kt @@ -0,0 +1,5 @@ +interface Tr : dynamic + +fun foo() {} + +class C where T : dynamic diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/typealiasExpandingToDynamic.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/typealiasExpandingToDynamic.kt index a68e6ca1793..e5241ae0b4c 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/typealiasExpandingToDynamic.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/typealiasExpandingToDynamic.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL typealias Dyn = dynamic typealias Dyn2 = Dyn typealias Dyn3 = Dyn2 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/typealiasWithAnnotatedDynamic.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/typealiasWithAnnotatedDynamic.fir.kt new file mode 100644 index 00000000000..b68ceadab24 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/typealiasWithAnnotatedDynamic.fir.kt @@ -0,0 +1,16 @@ +@Target(AnnotationTarget.TYPE) +annotation class Ann1 + +@Target(AnnotationTarget.TYPE) +annotation class Ann2 + +typealias AnnGenList = List<@Ann1 T> +typealias TestAnnGen1 = AnnGenList +typealias TestAnnGen2 = AnnGenList<@Ann2 dynamic> +typealias TestAnnGen3 = AnnGenList<@Ann1 dynamic> + +fun useAnnGen1(x: TestAnnGen1) = x +fun useAnnGen2(x: TestAnnGen2) = x + +fun testUseAnnGen1(x: List) = useAnnGen1(x) +fun testUseAnnGen2(x: List) = useAnnGen2(x) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/typealiasWithDynamic.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/typealiasWithDynamic.kt index c6e1aa941d3..3f2ebbb22c1 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/typealiasWithDynamic.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/typealiasWithDynamic.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL typealias Test1 = List typealias Test2 = (dynamic) -> dynamic @@ -10,4 +11,4 @@ fun useGen1(x: TestGen1) = x fun useGen2(x: TestGen2) = x fun testUseGen1(x: List) = useGen1(x) -fun testUseGen2(x: List>) = useGen2(x) +fun testUseGen2(x: List>) = useGen2(x) \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/varargs.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/varargs.fir.kt new file mode 100644 index 00000000000..4a9db6f50f2 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/varargs.fir.kt @@ -0,0 +1,13 @@ +// !MARK_DYNAMIC_CALLS + +fun test() { + v() + v(1) + v(1, "") +} + +fun v(vararg d: dynamic) { + for (dd in d) { + dd.foo() + } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/export/extendingNonExportedType.kt b/compiler/testData/diagnostics/testsWithJsStdLib/export/extendingNonExportedType.kt index 0fd9757a54b..f633328a7c6 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/export/extendingNonExportedType.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/export/extendingNonExportedType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !OPT_IN: kotlin.js.ExperimentalJsExport // !RENDER_DIAGNOSTICS_MESSAGES diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/export/jsExportOnNestedDeclarations.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/export/jsExportOnNestedDeclarations.fir.kt new file mode 100644 index 00000000000..5d98e1659c0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/export/jsExportOnNestedDeclarations.fir.kt @@ -0,0 +1,22 @@ +// !OPT_IN: kotlin.js.ExperimentalJsExport + +package foo + +class C1 { + @JsExport + fun f1() {} + + @JsExport + val p: Int = 10 + + @JsExport + object O +} + +fun f2() { + @JsExport + fun f3() {} + + @JsExport + class C2 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiers.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiers.fir.kt new file mode 100644 index 00000000000..1cf505c7f60 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiers.fir.kt @@ -0,0 +1,46 @@ +// !OPT_IN: kotlin.js.ExperimentalJsExport +// !RENDER_DIAGNOSTICS_MESSAGES + +package foo + +@JsExport +fun delete() {} + +@JsExport +val instanceof = 4 + +@JsExport +class eval + +@JsExport +@JsName("await") +fun foo() {} + +@JsExport +@JsName("this") +val bar = 4 + +@JsExport +@JsName("super") +class Baz + +@JsExport +@JsName("default") +class DefDef + +@JsExport +class Test { + fun instanceof() {} + + @JsName("eval") + fun test() {} +} + +@JsExport +object NaN + +@JsExport +enum class Nums { + Infinity, + undefined +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiersInExportedFile.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiersInExportedFile.fir.kt new file mode 100644 index 00000000000..9516ab98d14 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiersInExportedFile.fir.kt @@ -0,0 +1,34 @@ +// !OPT_IN: kotlin.js.ExperimentalJsExport +// !RENDER_DIAGNOSTICS_MESSAGES +@file:JsExport + +package foo + +fun delete() {} + +val instanceof = 4 + +class eval + +@JsName("await") +fun foo() {} + +@JsName("this") +val bar = 4 + +@JsName("super") +class Baz + +class Test { + fun instanceof() {} + + @JsName("eval") + fun test() {} +} + +object NaN + +enum class Nums { + Infinity, + undefined +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsName.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsName.fir.kt new file mode 100644 index 00000000000..fb403ddd9db --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsName.fir.kt @@ -0,0 +1,15 @@ +// !OPT_IN: kotlin.js.ExperimentalJsExport +// !RENDER_DIAGNOSTICS_MESSAGES + +package foo + +@JsExport +class C(val x: String) { + constructor(x: Int): this(x.toString()) +} + +@JsExport +class C2(val x: String) { + @JsName("JsNameProvided") + constructor(x: Int): this(x.toString()) +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsNameInExportedFile.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsNameInExportedFile.fir.kt new file mode 100644 index 00000000000..2c8acd755f3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsNameInExportedFile.fir.kt @@ -0,0 +1,14 @@ +// !OPT_IN: kotlin.js.ExperimentalJsExport +// !RENDER_DIAGNOSTICS_MESSAGES +@file:JsExport + +package foo + +class C(val x: String) { + constructor(x: Int): this(x.toString()) +} + +class C2(val x: String) { + @JsName("JsNameProvided") + constructor(x: Int): this(x.toString()) +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/export/unexportableTypesInSignature.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/export/unexportableTypesInSignature.fir.kt new file mode 100644 index 00000000000..fc2befe0616 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/export/unexportableTypesInSignature.fir.kt @@ -0,0 +1,56 @@ +// !OPT_IN: kotlin.js.ExperimentalJsExport +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !RENDER_DIAGNOSTICS_MESSAGES + +package foo + +class C + +@JsExport +fun foo(x: C) { +} + +@JsExport +fun bar() = C() + +@JsExport +val x: C = C() + +@JsExport +var x2: C + get() = C() + set(value) { } + +@JsExport +class A( + val x: C, + y: C +) { + fun foo(x: C) = x + + val x2: C = C() + + var x3: C + get() = C() + set(value) { } +} + +@JsExport +fun foo2() { +} + +@JsExport +fun foo3(x: Unit) { +} + +@JsExport +fun foo4(x: () -> Unit) { +} + +@JsExport +fun foo5(x: (Unit) -> Unit) { +} + +@JsExport +fun foo6(x: (A) -> A) { +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/export/unexportableTypesInTypeParameters.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/export/unexportableTypesInTypeParameters.fir.kt new file mode 100644 index 00000000000..b4890754f11 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/export/unexportableTypesInTypeParameters.fir.kt @@ -0,0 +1,25 @@ +// !OPT_IN: kotlin.js.ExperimentalJsExport +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !RENDER_DIAGNOSTICS_MESSAGES + +package foo + +abstract class C +interface I + +@JsExport +fun foo() { } + +@JsExport +class A + +@JsExport +interface I2 where T : C, T : I + +@JsExport +class B(val a: T, val b: Comparable) { + val c: Comparable = b +} + +@JsExport +class D(val a: T, val b: Array) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/export/wrongExportedDeclaration.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/export/wrongExportedDeclaration.fir.kt new file mode 100644 index 00000000000..2122f4cef6a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/export/wrongExportedDeclaration.fir.kt @@ -0,0 +1,48 @@ +// !OPT_IN: kotlin.js.ExperimentalJsExport +// !RENDER_DIAGNOSTICS_MESSAGES +// !DIAGNOSTICS: -INLINE_CLASS_DEPRECATED + +package foo + +@JsExport +inline fun inlineReifiedFun(x: Any) = x is T + +@JsExport +suspend fun suspendFun() { } + +@JsExport +val String.extensionProperty + get() = this.length + +@JsExport +annotation class AnnotationClass + +@JsExport +interface SomeInterface + +@JsExport +external interface GoodInterface + +@JsExport +interface InterfaceWithCompanion { + companion object { + fun foo() = 42 + } +} + +@JsExport +interface OuterInterface { + class Nested +} + +@JsExport +value class A(val a: Int) + +@JsExport +inline class B(val b: Int) + +@JsExport +inline value class C(val c: Int) + +@JsExport +value inline class D(val d: Int) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/export/wrongExportedDeclarationInExportedFile.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/export/wrongExportedDeclarationInExportedFile.fir.kt new file mode 100644 index 00000000000..6f3e688790a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/export/wrongExportedDeclarationInExportedFile.fir.kt @@ -0,0 +1,15 @@ +// !OPT_IN: kotlin.js.ExperimentalJsExport +// !RENDER_DIAGNOSTICS_MESSAGES + +@file:JsExport + +package foo + +inline fun inlineReifiedFun(x: Any) = x is T + +suspend fun suspendFun() { } + +val String.extensionProperty + get() = this.length + +annotation class AnnotationClass diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/funConstructorCallJS.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/funConstructorCallJS.fir.kt new file mode 100644 index 00000000000..e44489fec53 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/funConstructorCallJS.fir.kt @@ -0,0 +1,10 @@ +fun interface Foo { + fun invoke(): T +} + +fun test() { + Foo { } + Foo { } + Foo { } + Foo { "" } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/implementingFunction.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/implementingFunction.fir.kt new file mode 100644 index 00000000000..dd0991decff --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/implementingFunction.fir.kt @@ -0,0 +1,9 @@ +abstract class A : () -> Unit + +object B : (String, Int) -> Long { + override fun invoke(a: String, B: Int) = 23L +} + +abstract class C : kotlin.Function1 + +abstract class D : C() diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/inline/Reified.kt b/compiler/testData/diagnostics/testsWithJsStdLib/inline/Reified.kt index b8897e923ff..3ea5bbb4365 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/inline/Reified.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/inline/Reified.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL class C<reified T> val <reified T> T.v: T diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/argumentIsLiteral.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/argumentIsLiteral.fir.kt new file mode 100644 index 00000000000..5d376d4a646 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/argumentIsLiteral.fir.kt @@ -0,0 +1,24 @@ +val a = "1" + +fun nonConst(): String = "1" + +fun test() { + val b = "b" + + js(a) + js((b)) + js(("c")) + js(3) + js(3 + 2) + js(1.0f) + js(true) + js("$a") + js("${1}") + js("$b;") + js("${b}bb") + js(a + a) + js("a" + "a") + js("ccc") + + js(nonConst()) +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/badAssignment.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/badAssignment.fir.kt new file mode 100644 index 00000000000..83a609d6284 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/badAssignment.fir.kt @@ -0,0 +1,4 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +fun Int.foo(x: Int) { + js("this = x;") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/deleteOperation.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/deleteOperation.fir.kt new file mode 100644 index 00000000000..e07dd1adc65 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/deleteOperation.fir.kt @@ -0,0 +1,8 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(x: Any) { + js("delete x.foo;") + js("delete x['bar'];") + js("delete x.baz();") + js("delete this;") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/error.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/error.fir.kt new file mode 100644 index 00000000000..329b808e742 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/error.fir.kt @@ -0,0 +1,25 @@ +val code = """ + var s = "hello" + + ); +""" + +fun main(): Unit { + js("var = 10;") + + js("""var = 10;""") + + js("""var + = 777; + """) + + js(""" + var = 777; + """) + + js("var " + " = " + "10;") + + val n = 10 + js("var = $n;") + + js(code) +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/noJavaScriptProduced.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/noJavaScriptProduced.fir.kt new file mode 100644 index 00000000000..be4f81c1449 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/noJavaScriptProduced.fir.kt @@ -0,0 +1,16 @@ +fun test() { + js("") + js(" ") + js(""" + """) + + val empty = "" + js(empty) + + val whitespace = " " + js(whitespace) + + val multiline = """ + """ + js(multiline) +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/warning.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/warning.fir.kt new file mode 100644 index 00000000000..9407dd89d1d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/warning.fir.kt @@ -0,0 +1,10 @@ +fun main(): Unit { + js("var a = 08;") + + js("""var a = + + 08;""") + + val code = "var a = 08;" + js(code) +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/jvmDeclarations/cloneable.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/jvmDeclarations/cloneable.fir.kt new file mode 100644 index 00000000000..412daba8218 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/jvmDeclarations/cloneable.fir.kt @@ -0,0 +1,3 @@ +import kotlin.Cloneable + +fun cloneable(): Cloneable = intArrayOf(42) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/localClassMetadata.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/localClassMetadata.fir.kt new file mode 100644 index 00000000000..533b3c5bb54 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/localClassMetadata.fir.kt @@ -0,0 +1,80 @@ +// MODULE: lib +// FILE: lib.kt + +interface I { + fun foo(): String +} + +abstract class A { + abstract fun bar(): String +} + +abstract class G { + abstract fun baz(): T +} + +class C { + private val propA = object : A() { + override fun bar() = "propA.bar" + + fun x() = "OK" + } + + private val propI = object : I { + override fun foo() = "propI.foo" + + fun x() = "OK" + } + + private val propAI = object : A(), I { + override fun foo() = "propAI.foo" + + override fun bar() = "propAI.bar" + + fun x() = "OK" + } + + private val propG = object : G() { + override fun baz() = "propG.baz" + + fun x() = "OK" + } + + private val propOI = object { + inner class D { + fun df() {} + } + fun d(): D = D() + }.d() + + private val propL = run { + class L { + fun l() = "propL.l" + } + L() + } + + private val propL2 = run { + class L { + inner class L1 { + inner class L2 { + fun l2() = "propL2.l2" + } + } + } + + L().L1().L2() + } +} + +// MODULE: main(lib) +// FILE: main.kt +fun test() { + println(C().propA.x()) + println(C().propI.x()) + println(C().propAI.x()) + println(C().propG.x()) + println(C().propOI.df()) + println(C().propL.l()) + println(C().propL2.l2()) +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/module/dualModuleFromUmd.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/module/dualModuleFromUmd.fir.kt new file mode 100644 index 00000000000..421ea176c66 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/module/dualModuleFromUmd.fir.kt @@ -0,0 +1,29 @@ +// MODULE: m1 +// FILE: a.kt +package foo + +import kotlin.js.* + +@JsModule("A") +external object A { + fun f(): Int + + val g: Int +} + +@JsNonModule +external open class B { + fun foo(): Int +} + +// MODULE: m2(m1) +// MODULE_KIND: UMD +// FILE: c.kt +package bar + +import foo.* + +fun box() { + A.f()+A.g + B() +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/module/incompleteReifiedArg.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/module/incompleteReifiedArg.fir.kt new file mode 100644 index 00000000000..2e4fd923b81 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/module/incompleteReifiedArg.fir.kt @@ -0,0 +1,5 @@ +inline fun bar() {} + +fun foo() { + bar() +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/module/jsModuleNonExternal.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/module/jsModuleNonExternal.fir.kt new file mode 100644 index 00000000000..f755c753b7e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/module/jsModuleNonExternal.fir.kt @@ -0,0 +1,9 @@ +@file:JsModule("lib") + +class A { + class B + + fun bar() {} +} + +fun foo() = "OK" diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/module/jsModuleWithoutParameters.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/module/jsModuleWithoutParameters.fir.kt new file mode 100644 index 00000000000..b4afe2b9559 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/module/jsModuleWithoutParameters.fir.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -NO_VALUE_FOR_PARAMETER, -CONSTANT_EXPECTED_TYPE_MISMATCH +// This should not crash +package foo + +@JsModule +external fun foo(x: Int): Int + +@JsModule(23) +external fun bar(x: Int): Int diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/module/jsVarProhibited.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/module/jsVarProhibited.fir.kt new file mode 100644 index 00000000000..54b53b28a2a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/module/jsVarProhibited.fir.kt @@ -0,0 +1,7 @@ +package foo + +@JsModule("bar") +external var bar: Int = definedExternally + +@JsNonModule +external var baz: Int = definedExternally diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/module/nestedProhibited.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/module/nestedProhibited.fir.kt new file mode 100644 index 00000000000..0c4aa682f60 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/module/nestedProhibited.fir.kt @@ -0,0 +1,19 @@ +@file:JsModule("foo") +package foo + +@JsModule("A") +external class A { + class Nested +} + +@JsModule("B") +external object B + +@JsModule("foo") +external fun foo(): Int + +@JsModule("bar") +external val bar: Int + +@JsNonModule +external val baz: Int diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/module/prohibitedOnNonNative.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/module/prohibitedOnNonNative.fir.kt new file mode 100644 index 00000000000..fe0e5b3c089 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/module/prohibitedOnNonNative.fir.kt @@ -0,0 +1,16 @@ +package foo + +@JsModule("A") +class A + +@JsModule("B") +object B + +@JsModule("foo") +fun foo() = 23 + +@JsModule("bar") +val bar = 42 + +@JsNonModule +val baz = 99 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/module/wrongCallToModule.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/module/wrongCallToModule.fir.kt new file mode 100644 index 00000000000..9f02d1610d3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/module/wrongCallToModule.fir.kt @@ -0,0 +1,61 @@ +// MODULE: m1 +// FILE: a.kt +package foo + +import kotlin.js.* + +@JsModule("A") +external object A { + fun f(): Int + + val g: Int +} + +@JsModule("B") +external open class B { + fun foo(): Int + + class Nested +} + +@JsModule("bar") +external fun bar(): Unit + +// MODULE: m2(m1) +// FILE: b.kt +// TODO: it's hard to test @JsNonModule on file from an external module +@file:JsModule("foo") +package foo + +external fun baz(): Unit + +// FILE: c.kt +package bar + +import foo.* + +fun box() { + A.f()+A.g + B() + bar() + baz() + + println(::bar.name) + println(::baz.name) + println(A::f.name) + + B.Nested() + + boo(null) + boo(null as B?) + boo(null) + + println(B::class) + println(B.Nested::class) +} + +external class DerivedB : B + +inline fun boo(x: T) { + println("${T::class.simpleName}: $x") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/module/wrongCallToNonModule.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/module/wrongCallToNonModule.fir.kt new file mode 100644 index 00000000000..51c3c9a718b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/module/wrongCallToNonModule.fir.kt @@ -0,0 +1,53 @@ +// MODULE: m1 +// FILE: a.kt +package foo + +import kotlin.js.* + +@JsNonModule +external object A { + fun f(): Int + + val g: Int +} + +@JsNonModule +external open class B { + fun foo(): Int + + class Nested +} + +@JsNonModule +external fun bar(): Unit + +// MODULE: m2(m1) +// MODULE_KIND: AMD +// TODO: it's hard to test @JsNonModule on file from an external module +// FILE: c.kt +package bar + +import foo.* + +fun box() { + A.f()+A.g + B() + bar() + B.Nested() + + println(::bar.name) + println(A::f.name) + + boo(null) + boo(null as B?) + boo(null) + + println(B::class) + println(B.Nested::class) +} + +external class DerivedB : B + +inline fun boo(x: T) { + println("${T::class.simpleName}: $x") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/bridgeClash.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/bridgeClash.fir.kt new file mode 100644 index 00000000000..401f7b6dac2 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/bridgeClash.fir.kt @@ -0,0 +1,18 @@ +interface I { + fun foo() +} + +interface J { + @JsName("bar") + fun foo() +} + +interface K : I, J { + override fun foo() +} + +interface L : K { + override fun foo() + + fun bar() +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/builtinClash.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/builtinClash.fir.kt new file mode 100644 index 00000000000..6d9873173c7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/builtinClash.fir.kt @@ -0,0 +1,56 @@ +class C { + class prototype + + class length + + class `$metadata$` + + fun constructor() {} +} + +class D { + private class prototype + + private class length + + private class `$metadata$` + + private fun constructor() {} +} + +class E { + @JsName("prototype") + class D + + @JsName("constructor") + fun f() {} +} + +class F { + @JsName("A") + class prototype + + @JsName("B") + class length + + @JsName("f") + fun constructor() {} +} + +class prototype + +class length + +fun constructor() { +} + +fun f() { + class prototype + class length + + fun constructor() {} +} + +external interface Object { + val constructor: Any? +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/classAndFunction.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/classAndFunction.fir.kt new file mode 100644 index 00000000000..f4b67b3835c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/classAndFunction.fir.kt @@ -0,0 +1,5 @@ +package foo + +class A(val x: Int) + +fun A() {} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/classAndTypealias.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/classAndTypealias.kt index 1cd013c422e..38068e684c2 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/name/classAndTypealias.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/classAndTypealias.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL package foo @JsName("B") class A(val x: Int) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/classLevelMethodAndProperty.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/classLevelMethodAndProperty.fir.kt new file mode 100644 index 00000000000..580a301663d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/classLevelMethodAndProperty.fir.kt @@ -0,0 +1,7 @@ +package foo + +class A { + fun bar() = 23 + + val bar = 23 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/conflictingNamesFromSuperclass.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/conflictingNamesFromSuperclass.fir.kt new file mode 100644 index 00000000000..ff85da4a2e5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/conflictingNamesFromSuperclass.fir.kt @@ -0,0 +1,23 @@ +interface A { + @JsName("foo") fun f() +} + +interface B { + @JsName("foo") fun g() +} + +class C : A, B { + override fun f() {} + + override fun g() {} +} + +abstract class D : A, B + +open class E { + open fun f() {} + + open fun g() {} +} + +class F : E(), A, B diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/declarationClash.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/declarationClash.kt index acf76ddc384..33f777aff96 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/name/declarationClash.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/declarationClash.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FILE: first.kt package foo diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/extensionPropertyAndMethod.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/extensionPropertyAndMethod.fir.kt new file mode 100644 index 00000000000..6e763f81fc0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/extensionPropertyAndMethod.fir.kt @@ -0,0 +1,8 @@ +package foo + +class A + +fun A.get_bar() = 23 + +val A.bar: Int + get() = 42 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/illegalName.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/illegalName.fir.kt new file mode 100644 index 00000000000..1c3562930c5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/illegalName.fir.kt @@ -0,0 +1,25 @@ +private fun ` .private `(): String = TODO("") + +fun ` .public `(): String = TODO("") + +@JsName(" __ ") +fun foo(): String = TODO("") + +@JsName(" ___ ") +private fun bar(): String = TODO("") + +@JsName("validName") +private fun ` .private with @JsName `(): String = TODO("") + +private class ` .private class ` { + val ` .field. ` = "" +} + +val x: Int + @JsName(".") + get() = TODO("") + +fun box(x: dynamic) { + x.`foo-bar`() + x.`ba-z` +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/illegalNameIR.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/illegalNameIR.kt index 22eca4762a8..ac0c400bc99 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/name/illegalNameIR.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/illegalNameIR.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // SKIP_TXT // IGNORE_BACKEND: JS // !LANGUAGE: +JsAllowInvalidCharsIdentifiersEscaping diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/illegalPackageName.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/illegalPackageName.fir.kt new file mode 100644 index 00000000000..4d78f0325d5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/illegalPackageName.fir.kt @@ -0,0 +1,3 @@ +package `//` + +class A diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameAndOverridden.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameAndOverridden.fir.kt new file mode 100644 index 00000000000..df974383a3a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameAndOverridden.fir.kt @@ -0,0 +1,9 @@ +package foo + +open class Super { + fun foo() = 23 +} + +class Sub : Super() { + @JsName("foo") fun bar() = 42 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameClash.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameClash.fir.kt new file mode 100644 index 00000000000..3f0fac6f1bc --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameClash.fir.kt @@ -0,0 +1,5 @@ +package foo + +@JsName("x") fun foo(x: Int) = x + +@JsName("x") fun bar() = 42 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameClashWithDefault.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameClashWithDefault.fir.kt new file mode 100644 index 00000000000..e691a11a05d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameClashWithDefault.fir.kt @@ -0,0 +1,5 @@ +package foo + +@JsName("bar") fun foo(x: Int) = x + +fun bar() = 42 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameMissingOnAccessors.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameMissingOnAccessors.fir.kt new file mode 100644 index 00000000000..df46a3eeddf --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameMissingOnAccessors.fir.kt @@ -0,0 +1,23 @@ +package foo + +class A { + var x: Int + @JsName("get_x") get() = 23 + set(value) {} + + var y: Int + get() = 23 + @JsName("set_y") set(value) {} + + var z: Int + @JsName("get_z") get() = 23 + @JsName("set_z") set(value) {} +} + +var xx: Int + @JsName("get_xx") get() = 23 + set(value) {} + +var A.ext: Int + @JsName("get_ext") get() = 23 + set(value) {} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameOnAccessors.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameOnAccessors.fir.kt new file mode 100644 index 00000000000..eebd6729039 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameOnAccessors.fir.kt @@ -0,0 +1,7 @@ +package foo + +class A { + var x: Int + @JsName("xx") get() = 0 + @JsName("xx") set(value) {} +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameOnOverride.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameOnOverride.fir.kt new file mode 100644 index 00000000000..7b0682e5c83 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameOnOverride.fir.kt @@ -0,0 +1,19 @@ +package foo + +open class A { + @JsName("foo_") open fun foo() = 23 + + @JsName("bar_") open val bar = 123 + + open val baz: Int + @JsName("getBaz_") get() = 55 +} + +class B : A() { + @JsName("foo__") override fun foo() = 42 + + @JsName("bar__") override val bar = 142 + + override val baz: Int + @JsName("getBaz__") get() = 155 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameOnPropertyAndAccessor.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameOnPropertyAndAccessor.fir.kt new file mode 100644 index 00000000000..52c7c419311 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameOnPropertyAndAccessor.fir.kt @@ -0,0 +1,21 @@ +package foo + +class A { + @JsName("x_") val x: Int + @JsName("get_x") get() = 23 + + @JsName("y_") val y = 0 + + @JsName("m_") var m: Int + @JsName("get_m") get() = 23 + @JsName("set_m") set(value) {} +} + +@JsName("xx_") val xx: Int + @JsName("get_xx") get() = 23 + +@JsName("yy_") val yy = 0 + +@JsName("mm_") var mm: Int + @JsName("get_mm") get() = 23 + @JsName("set_mm") set(value) {} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNamePrihibitedOnPrimaryConstructor.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNamePrihibitedOnPrimaryConstructor.fir.kt new file mode 100644 index 00000000000..bada0d62de1 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNamePrihibitedOnPrimaryConstructor.fir.kt @@ -0,0 +1,3 @@ +package foo + +class A @JsName("B") constructor() diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameProhibitedOnExtensionProperty.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameProhibitedOnExtensionProperty.fir.kt new file mode 100644 index 00000000000..f98491be9b7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameProhibitedOnExtensionProperty.fir.kt @@ -0,0 +1,9 @@ +package foo + +class A + +@JsName("xx") val A.x: Int + get() = 23 + +@property:JsName("yy") val A.y: Int + get() = 42 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameUseTargetOnProperty.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameUseTargetOnProperty.fir.kt new file mode 100644 index 00000000000..1bf672df809 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameUseTargetOnProperty.fir.kt @@ -0,0 +1,5 @@ +class A { + @property:JsName("x_") @get:JsName("getX_") val x: Int = 0 + + @get:JsName("getY_") var y: Int = 0 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameWithoutParameter.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameWithoutParameter.fir.kt new file mode 100644 index 00000000000..f3576680f6d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameWithoutParameter.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -NO_VALUE_FOR_PARAMETER, -CONSTANT_EXPECTED_TYPE_MISMATCH +// This should not crash, see KT-14752 +package foo + +@JsName fun foo(x: Int) = x + +@JsName(23) fun bar(x: Int) = x diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/methodAndMethod.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/methodAndMethod.fir.kt new file mode 100644 index 00000000000..3d0ed276fa9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/methodAndMethod.fir.kt @@ -0,0 +1,5 @@ +package foo + +fun bar(x: Int) = x + +fun `bar_za3lpa$`() = 42 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/nameSwapInOverride.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/nameSwapInOverride.fir.kt new file mode 100644 index 00000000000..66002f98bf4 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/nameSwapInOverride.fir.kt @@ -0,0 +1,21 @@ +interface I { + @JsName("bar") + fun foo() + + @JsName("foo") + fun bar() +} + +interface J { + fun foo() + + fun bar() +} + +class A : I, J { + // Duplicate diagnostics are expected here, since `bar()` function gets both `foo` and `bar` names and clashes with both + // names of `foo()` function. + override fun bar() {} + + override fun foo() {} +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/overrideOverloadedNativeFunction.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/overrideOverloadedNativeFunction.fir.kt new file mode 100644 index 00000000000..c28351e23d6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/overrideOverloadedNativeFunction.fir.kt @@ -0,0 +1,9 @@ +external open class A { + open fun f(x: Int): Unit + + open fun f(x: String): Unit +} + +class InheritClass : A() { + override fun f(x: Int): Unit { } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/packageAndMethod.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/packageAndMethod.fir.kt new file mode 100644 index 00000000000..154ce6837b3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/packageAndMethod.fir.kt @@ -0,0 +1,11 @@ +// FILE: foo.kt + +package foo + +fun bar() = 23 + +// FILE: foobar.kt + +package foo.bar + +val x = 42 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/packageAndProperty.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/packageAndProperty.fir.kt new file mode 100644 index 00000000000..4e8b6cbda3c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/packageAndProperty.fir.kt @@ -0,0 +1,11 @@ +// FILE: foo.kt + +package foo + +val bar = 23 + +// FILE: foobar.kt + +package foo.bar + +val x = 42 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/privateJsNameClash.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/privateJsNameClash.fir.kt new file mode 100644 index 00000000000..bad5f53fc42 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/privateJsNameClash.fir.kt @@ -0,0 +1,5 @@ +package foo + +@JsName("bar") private fun foo(x: Int) = x + +fun bar() = 42 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/propertyAndMethodInImplementor.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/propertyAndMethodInImplementor.fir.kt new file mode 100644 index 00000000000..8123284e4d6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/propertyAndMethodInImplementor.fir.kt @@ -0,0 +1,9 @@ +package foo + +interface I { + fun foo() = 23 +} + +class Sub : I { + var foo = 42 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/propertyAndMethodInSubclass.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/propertyAndMethodInSubclass.fir.kt new file mode 100644 index 00000000000..a18d903cc5d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/propertyAndMethodInSubclass.fir.kt @@ -0,0 +1,9 @@ +package foo + +open class Super { + val foo = 23 +} + +class Sub : Super() { + fun foo() = 42 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/topLevelMethodAndJsNameConstructor.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/topLevelMethodAndJsNameConstructor.fir.kt new file mode 100644 index 00000000000..051449586e8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/topLevelMethodAndJsNameConstructor.fir.kt @@ -0,0 +1,7 @@ +package foo + +class A(val x: String) { + @JsName("aa") constructor(x: Int) : this("int $x") +} + +fun aa() {} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/topLevelMethodAndProperty.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/topLevelMethodAndProperty.fir.kt new file mode 100644 index 00000000000..361aa200e2f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/topLevelMethodAndProperty.fir.kt @@ -0,0 +1,5 @@ +package foo + +fun bar() = 23 + +val bar = 32 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/anonymousInitializer.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/anonymousInitializer.fir.kt new file mode 100644 index 00000000000..2503538c05a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/anonymousInitializer.fir.kt @@ -0,0 +1,5 @@ +external class A { + init { + definedExternally + } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/body.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/body.fir.kt new file mode 100644 index 00000000000..8d6a11c7517 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/body.fir.kt @@ -0,0 +1,30 @@ +external fun foo(): Int = definedExternally + +external fun bar(): Unit { + definedExternally +} + +external fun baz(): Int = 23 + +external fun f(x: Int, y: String = definedExternally): Unit + +external fun g(x: Int, y: String = ""): Unit + +external var a: Int + get() = definedExternally + set(value) { + definedExternally + } + +external val b: Int + get() = 23 + +external val c: Int = definedExternally + +external val d: Int = 23 + +external class C { + fun foo(): Int = definedExternally + + fun bar(): Int = 23 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/delegatedConstructorCall.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/delegatedConstructorCall.fir.kt new file mode 100644 index 00000000000..9c0f69efcee --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/delegatedConstructorCall.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -DEBUG_INFO_MISSING_UNRESOLVED + +external open class Base(x: Int) { + constructor(x: String) : this(23) + + constructor(x: String, y: String) : this("") +} + +external open class Derived1() : Base(23) { + constructor(x: Byte) : super(23) + + constructor(x: String) : super("") + + constructor(x: String, y: String) : super("") +} + +external open class Derived2() : Base("") diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/delegation.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/delegation.fir.kt new file mode 100644 index 00000000000..a41f6194a67 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/delegation.fir.kt @@ -0,0 +1,18 @@ +external interface I + +external object O : I + + +class Delegate { + operator fun getValue(thisRef: Any?, property: Any): String = "" + + operator fun setValue(thisRef: Any?, property: Any, value: String) {} +} + +external class A : I by O { + val prop by Delegate() + + var mutableProp by Delegate() +} + +external val topLevelProp by Delegate() diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/enumEntry.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/enumEntry.fir.kt new file mode 100644 index 00000000000..9a17d365032 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/enumEntry.fir.kt @@ -0,0 +1,7 @@ +external enum class E { + X, + Y { + fun foo() + }, + Z {} +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.fir.kt new file mode 100644 index 00000000000..3cdf8023cc8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionAndProperty.fir.kt @@ -0,0 +1,10 @@ +class A + +external fun A.foo(): Unit = definedExternally + +external var A.bar: String + get() = definedExternally + set(value) = definedExternally + +external val A.baz: String + get() = definedExternally diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionArgumentOrReturnType.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionArgumentOrReturnType.fir.kt new file mode 100644 index 00000000000..4be70a6344b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionArgumentOrReturnType.fir.kt @@ -0,0 +1,25 @@ +external fun foo(f: Int.() -> Int) + +external fun bar(vararg f: Int.() -> Int) + +external fun baz(): Int.() -> Int + +external val prop: Int.() -> Int + +external var prop2: Int.() -> Int + +external val propGet + get(): Int.() -> Int = definedExternally + +external var propSet + get(): Int.() -> Int = definedExternally + set(v: Int.() -> Int) = definedExternally + +external class A(f: Int.() -> Int) + +external data class B( + val a: Int.() -> Int, + var b: Int.() -> Int +) { + val c: Int.() -> Int +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/externalFunInterface.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/externalFunInterface.fir.kt new file mode 100644 index 00000000000..2eba53f9de8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/externalFunInterface.fir.kt @@ -0,0 +1,3 @@ +external fun interface I { + fun f() +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/externalInterfaceNested.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/externalInterfaceNested.fir.kt new file mode 100644 index 00000000000..fd07443247b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/externalInterfaceNested.fir.kt @@ -0,0 +1,11 @@ +external interface I { + interface J + + class C + + object O + + enum class E + + companion object +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/inheritance.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/inheritance.fir.kt new file mode 100644 index 00000000000..3593fd79261 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/inheritance.fir.kt @@ -0,0 +1,19 @@ +open class A + +interface I + +external open class B + +external class C : A + +external class D : B, I + +external interface K : I + +external enum class E { + X +} + +external enum class F : I { + X +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/inline.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/inline.fir.kt new file mode 100644 index 00000000000..99fc7706c87 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/inline.fir.kt @@ -0,0 +1,19 @@ +// !DIAGNOSTICS: -NOTHING_TO_INLINE + +inline external fun foo(): Unit + +inline external val bar: Int + get() = definedExternally + +external val baz: Int + inline get() = definedExternally + +external class A { + inline fun foo(): Unit + + inline val bar: Int + get() = definedExternally + + val baz: Int + inline get() = definedExternally +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClass.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClass.fir.kt new file mode 100644 index 00000000000..9ce0b240caa --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClass.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: +InlineClasses, -JvmInlineValueClasses + +external inline class C(val a: Int) { + fun foo() +} + +inline external enum class E { + A +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType.kt.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType.kt.fir.kt new file mode 100644 index 00000000000..065455f3f00 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType.kt.fir.kt @@ -0,0 +1,64 @@ +// !LANGUAGE: +InlineClasses, -JvmInlineValueClasses + +// FILE: uint.kt + +package kotlin + +inline class UInt(private val i: Int) + +// FILE: test.kt + +inline class SomeIC(val a: Int) + +external val l: SomeIC + +external val ll + get(): SomeIC = definedExternally + +external var r: SomeIC + +external var rr: SomeIC + get() = definedExternally + set(v: SomeIC) { definedExternally } + +external fun foo(): SomeIC +external fun foo(c: SomeIC): SomeIC +external fun foo(a: Int, c: SomeIC): SomeIC + +external fun foo(a: Int, vararg args: SomeIC) +external fun foo(a: Int, ui: UInt, vararg args: UInt) + +external class CC( + a: SomeIC, + val b: SomeIC, + var c: SomeIC +) { + val l: SomeIC + var r: SomeIC + + fun foo(): SomeIC + fun foo(c: SomeIC): SomeIC + fun foo(a: Int, c: SomeIC): SomeIC + + class N( + a: SomeIC, + val b: SomeIC, + var c: SomeIC + ) { + val l: SomeIC + var r: SomeIC + + fun foo(): SomeIC + fun foo(c: SomeIC): SomeIC + fun foo(a: Int, c: SomeIC): SomeIC + } +} + +external interface EI { + val l: SomeIC + var r: SomeIC + + fun foo(): SomeIC + fun foo(c: SomeIC): SomeIC + fun foo(a: Int, c: SomeIC): SomeIC +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType_allowed.kt.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType_allowed.kt.fir.kt new file mode 100644 index 00000000000..34864047ded --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineClassAsParameterOrReturnType_allowed.kt.fir.kt @@ -0,0 +1,65 @@ +// !LANGUAGE: +InlineClasses, -JvmInlineValueClasses, +JsAllowValueClassesInExternals +// !DIAGNOSTICS: +INLINE_CLASS_IN_EXTERNAL_DECLARATION_WARNING + +// FILE: uint.kt + +package kotlin + +inline class UInt(private val i: Int) + +// FILE: test.kt + +inline class SomeIC(val a: Int) + +external val l: SomeIC + +external val ll + get(): SomeIC = definedExternally + +external var r: SomeIC + +external var rr: SomeIC + get() = definedExternally + set(v: SomeIC) { definedExternally } + +external fun foo(): SomeIC +external fun foo(c: SomeIC): SomeIC +external fun foo(a: Int, c: SomeIC): SomeIC + +external fun foo(a: Int, vararg args: SomeIC) +external fun foo(a: Int, ui: UInt, vararg args: UInt) + +external class CC( + a: SomeIC, + val b: SomeIC, + var c: SomeIC +) { + val l: SomeIC + var r: SomeIC + + fun foo(): SomeIC + fun foo(c: SomeIC): SomeIC + fun foo(a: Int, c: SomeIC): SomeIC + + class N( + a: SomeIC, + val b: SomeIC, + var c: SomeIC + ) { + val l: SomeIC + var r: SomeIC + + fun foo(): SomeIC + fun foo(c: SomeIC): SomeIC + fun foo(a: Int, c: SomeIC): SomeIC + } +} + +external interface EI { + val l: SomeIC + var r: SomeIC + + fun foo(): SomeIC + fun foo(c: SomeIC): SomeIC + fun foo(a: Int, c: SomeIC): SomeIC +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineExtensionToNative.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineExtensionToNative.kt index fb4512bbb63..1a0f3803192 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineExtensionToNative.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/inlineExtensionToNative.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL external class A { class B } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/innerClass.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/innerClass.fir.kt new file mode 100644 index 00000000000..dffb71cb484 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/innerClass.fir.kt @@ -0,0 +1,9 @@ +external class C { + inner class Inner +} + +external enum class E { + X; + + inner class Inner +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalExtensionFun.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalExtensionFun.fir.kt new file mode 100644 index 00000000000..006b9f7a843 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalExtensionFun.fir.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION + +fun foo() { + @nativeGetter + fun Int.get(a: String): Int? = 1 + + @nativeGetter + fun Int.get2(a: Number): String? = "OK" + + @nativeGetter + fun Int.get3(a: Int): String? = "OK" + + @nativeGetter + fun Int.get(a: Any): Int? = 1 + + @nativeGetter + fun Int.get2(): String? = "OK" + + @nativeGetter + fun Int.get3(a: Any, b: Int, c: Any?): String? = "OK" + + @nativeGetter + fun Any.foo(a: Int = 1): Any? = "OK" +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNonNativeClassMembers.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNonNativeClassMembers.fir.kt new file mode 100644 index 00000000000..5c4c4da8769 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalNonNativeClassMembers.fir.kt @@ -0,0 +1,45 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -NON_TOPLEVEL_CLASS_DECLARATION, -DEPRECATION + +fun foo() { + class A { + @nativeGetter + fun get(a: String): Any? = null + + @nativeGetter + fun take(a: Number): String? = null + + @nativeGetter + fun foo(a: Double): String? = null + } + + class B { + @nativeGetter + val foo = 0 + } + + class C { + @nativeGetter + fun Int.get(a: String): Int? = 1 + + @nativeGetter + fun Int.get2(a: Number): String? = "OK" + + @nativeGetter + fun Int.get3(a: Int): String? = "OK" + + @nativeGetter + fun get(): Any? = null + + @nativeGetter + fun get(a: A): Any? = null + + @nativeGetter + fun foo(a: Int) {} + + @nativeGetter + fun bar(a: String): Int = 0 + + @nativeGetter + fun baz(a: Int = 0): Int? = 0 + } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalOtherDeclarations.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalOtherDeclarations.fir.kt new file mode 100644 index 00000000000..7cac9c47d7d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onLocalOtherDeclarations.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -NON_TOPLEVEL_CLASS_DECLARATION, -DEPRECATION + +fun foo() { + @nativeGetter + fun toplevelFun(): Any = 0 + + @nativeGetter + val toplevelVal = 0 + + @nativeGetter + class Foo {} +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.fir.kt new file mode 100644 index 00000000000..8dff53b9f0e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNativeClassMembers.fir.kt @@ -0,0 +1,57 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION + +external class A { + @nativeGetter + fun get(a: String): Any? = definedExternally + + @nativeGetter + fun take(a: Number): String? = definedExternally + + @nativeGetter + fun foo(a: Double): String? = definedExternally + + companion object { + @nativeGetter + fun get(a: String): Any? = definedExternally + + @nativeGetter + fun take(a: Number): String? = definedExternally + + @nativeGetter + fun foo(a: Double): String? = definedExternally + } +} + +external class B { + @nativeGetter + val foo: Int = definedExternally + + @nativeGetter + object Obj1 {} + + companion object { + @nativeGetter + val foo: Int = definedExternally + + @nativeGetter + object Obj2 {} + } +} + +external class C { + @nativeGetter + fun get(): Any? = definedExternally + + @nativeGetter + fun get(a: A): Any? = definedExternally + + @nativeGetter + fun foo(a: Int) { definedExternally } + + @nativeGetter + fun bar(a: String): Int = definedExternally + + @nativeGetter + fun baz(a: String = definedExternally): Int? = definedExternally + +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.fir.kt new file mode 100644 index 00000000000..c73fbf6ac3e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNativeClass.fir.kt @@ -0,0 +1,77 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION + +external class A { + class B { + class A { + @nativeGetter + fun get(a: String): Any? = definedExternally + + @nativeGetter + fun take(a: Number): String? = definedExternally + + @nativeGetter + fun foo(a: Double): String? = definedExternally + + companion object { + @nativeGetter + fun get(a: String): Any? = definedExternally + + @nativeGetter + fun take(a: Number): String? = definedExternally + + @nativeGetter + fun foo(a: Double): String? = definedExternally + } + } + + class B { + @nativeGetter + val foo: Int = definedExternally + + @nativeGetter + object Obj1 {} + + companion object { + @nativeGetter + val foo: Int = definedExternally + + @nativeGetter + object Obj2 {} + } + } + + class C { + @nativeGetter + fun get(): Any? = definedExternally + + @nativeGetter + fun get(a: A): Any? = definedExternally + + @nativeGetter + fun foo(a: Int) { definedExternally } + + @nativeGetter + fun bar(a: String): Int = definedExternally + + @nativeGetter + fun baz(a: Number = definedExternally): Int? = definedExternally + } + + object obj { + @nativeGetter + fun get(): Any? = definedExternally + + @nativeGetter + fun get(a: A): Any? = definedExternally + + @nativeGetter + fun foo(a: Int) { definedExternally } + + @nativeGetter + fun bar(a: String): Int = definedExternally + + @nativeGetter + fun baz(a: String = definedExternally): Int? = definedExternally + } + } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNonNativeClass.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNonNativeClass.fir.kt new file mode 100644 index 00000000000..cdbc04b02a0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNestedDeclarationsInsideNonNativeClass.fir.kt @@ -0,0 +1,112 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -NON_TOPLEVEL_CLASS_DECLARATION, -DEPRECATION + +class A { + class B { + class A { + @nativeGetter + fun get(a: String): Any? = null + + @nativeGetter + fun take(a: Number): String? = null + + @nativeGetter + fun foo(a: Double): String? = null + + companion object { + @nativeGetter + fun get(a: String): Any? = null + + @nativeGetter + fun take(a: Number): String? = null + + @nativeGetter + fun foo(a: Double): String? = null + } + } + + class B { + @nativeGetter + fun Int.get(a: String): Int? = 1 + + @nativeGetter + fun Int.get2(a: Number): String? = "OK" + + @nativeGetter + fun Int.get3(a: Int): String? = "OK" + + @nativeGetter + val foo = 0 + + @nativeGetter + object Obj1 {} + + companion object { + @nativeGetter + val foo = 0 + + @nativeGetter + object Obj2 {} + + @nativeGetter + fun Int.get(a: String): Int? = 1 + + @nativeGetter + fun Int.get2(a: Number): String? = "OK" + + @nativeGetter + fun Int.get3(a: Int): String? = "OK" + } + } + + class C { + @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 + } + + object obj { + @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: Double = 0.0): 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 + } + } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNonNativeClassMembers.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNonNativeClassMembers.fir.kt new file mode 100644 index 00000000000..23d6d845445 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onNonNativeClassMembers.fir.kt @@ -0,0 +1,65 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION + +class A { + @nativeGetter + fun get(a: String): Any? = null + + @nativeGetter + fun take(a: Number): String? = null + + @nativeGetter + fun foo(a: Double): String? = null + + companion object { + @nativeGetter + fun get(a: String): Any? = null + + @nativeGetter + fun take(a: Number): String? = null + + @nativeGetter + fun foo(a: Double): String? = null + } +} + +class B { + @nativeGetter + val foo = 0 + + @nativeGetter + object Obj1 {} + + companion object { + @nativeGetter + val foo = 0 + + @nativeGetter + object Obj2 {} + } +} + +class C { + @nativeGetter + fun Int.get(a: String): Int? = 1 + + @nativeGetter + fun Int.get2(a: Number): String? = "OK" + + @nativeGetter + fun Int.get3(a: Int): String? = "OK" + + @nativeGetter + fun get(): Any? = null + + @nativeGetter + fun get(a: A): Any? = null + + @nativeGetter + fun foo(a: Int) {} + + @nativeGetter + fun bar(a: String): Int = 0 + + @nativeGetter + fun baz(a: String = "foo"): Int? = 0 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelExtensionFun.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelExtensionFun.fir.kt new file mode 100644 index 00000000000..2a71d183832 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelExtensionFun.fir.kt @@ -0,0 +1,22 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION + +@nativeGetter +fun Int.get(a: String): Int? = 1 + +@nativeGetter +fun Int.get2(a: Number): String? = "OK" + +@nativeGetter +fun Int.get3(a: Int): String? = "OK" + +@nativeGetter +fun Int.baz(a: Int = 0): String? = "OK" + +@nativeGetter +fun Int.get(a: Any): Int? = 1 + +@nativeGetter +fun Int.get2(): String? = "OK" + +@nativeGetter +fun Int.get3(a: Any, b: Int, c: Any?): String? = "OK" diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelOtherDeclarations.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelOtherDeclarations.fir.kt new file mode 100644 index 00000000000..40bbd7615b9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeGetter/onToplevelOtherDeclarations.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION + +@nativeGetter +fun toplevelFun(): Any = 0 + +@nativeGetter +val toplevelVal = 0 + +@nativeGetter +class Foo {} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalExtensionFun.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalExtensionFun.kt index 332848d4937..d027b057d19 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalExtensionFun.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalExtensionFun.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION fun foo() { diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalNonNativeClassMembers.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalNonNativeClassMembers.fir.kt new file mode 100644 index 00000000000..3957421f690 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalNonNativeClassMembers.fir.kt @@ -0,0 +1,25 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -NON_TOPLEVEL_CLASS_DECLARATION, -DEPRECATION + +fun foo() { + class A { + @nativeInvoke + fun foo() {} + + @nativeInvoke + fun invoke(a: String): Int = 0 + + @nativeInvoke + fun Int.ext() = 1 + + @nativeInvoke + fun Int.invoke(a: String, b: Int) = "OK" + + val anonymous = object { + @nativeInvoke + fun foo() {} + + @nativeInvoke + fun invoke(a: String): Int = 0 + } + } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalOtherDeclarations.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalOtherDeclarations.fir.kt new file mode 100644 index 00000000000..9dc7b983aea --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onLocalOtherDeclarations.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -NON_TOPLEVEL_CLASS_DECLARATION, -DEPRECATION + +fun foo() { + @nativeInvoke + fun toplevelFun() {} + + @nativeInvoke + val toplevelVal = 0 + + @nativeInvoke + class Foo {} +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.kt index b5a59d990a4..3b82fff7438 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNativeClassMembers.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION external class A { diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.kt index 9c0d70816b3..f46c498a7cd 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNativeClass.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION external class A { diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNonNativeClass.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNonNativeClass.fir.kt new file mode 100644 index 00000000000..aa8bc287f18 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNestedDeclarationsInsideNonNativeClass.fir.kt @@ -0,0 +1,43 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -NON_TOPLEVEL_CLASS_DECLARATION, -DEPRECATION + +class A { + class B { + class C { + @nativeInvoke + fun foo() {} + + @nativeInvoke + fun invoke(a: String): Int = 0 + + @nativeInvoke + fun Int.ext() = 1 + + @nativeInvoke + fun Int.invoke(a: String, b: Int) = "OK" + } + + object obj { + @nativeInvoke + fun foo() {} + + @nativeInvoke + fun invoke(a: String): Int = 0 + } + + companion object { + @nativeInvoke + fun foo() {} + + @nativeInvoke + fun invoke(a: String): Int = 0 + } + + val anonymous = object { + @nativeInvoke + fun foo() {} + + @nativeInvoke + fun invoke(a: String): Int = 0 + } + } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNonNativeClassMembers.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNonNativeClassMembers.fir.kt new file mode 100644 index 00000000000..73dbce1bc3e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onNonNativeClassMembers.fir.kt @@ -0,0 +1,35 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION + +class A { + @nativeInvoke + fun foo() {} + + @nativeInvoke + fun invoke(a: String): Int = 0 + + @nativeInvoke + fun Int.ext() = 1 + + @nativeInvoke + fun Int.invoke(a: String, b: Int) = "OK" + + @nativeInvoke + val baz = 0 + + @nativeInvoke + object Obj {} + + companion object { + @nativeInvoke + fun foo() {} + + @nativeInvoke + fun invoke(a: String): Int = 0 + + @nativeInvoke + fun Int.ext() = 1 + + @nativeInvoke + fun Int.invoke(a: String, b: Int) = "OK" + } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onToplevelExtensionFun.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onToplevelExtensionFun.kt index 9165eb39fc4..371ca0b1a10 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onToplevelExtensionFun.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onToplevelExtensionFun.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION @nativeInvoke diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onToplevelOtherDeclarations.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onToplevelOtherDeclarations.fir.kt new file mode 100644 index 00000000000..ad6bfcee373 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeInvoke/onToplevelOtherDeclarations.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION + +@nativeInvoke +fun toplevelFun() {} + +@nativeInvoke +val toplevelVal = 0 + +@nativeInvoke +class Foo {} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalExtensionFun.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalExtensionFun.fir.kt new file mode 100644 index 00000000000..d889b573d86 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalExtensionFun.fir.kt @@ -0,0 +1,33 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION + +fun foo() { + @nativeSetter + fun Int.set(a: String, v: Int) {} + + @nativeSetter + fun Int.set2(a: Number, v: String?): Any? = null + + @nativeSetter + fun Int.set3(a: Double, v: String) = "OK" + + @nativeSetter + fun Int.set4(a: Double, v: String): Any = 1 + + @nativeSetter + fun Int.set5(a: Double, v: String): CharSequence = "OK" + + @nativeSetter + fun Int.set6(a: Double, v: String): Number = 1 + + @nativeSetter + fun Int.set(a: Any): Int? = 1 + + @nativeSetter + fun Int.set2(): String? = "OK" + + @nativeSetter + fun Int.set3(a: Any, b: Int, c: Any?) {} + + @nativeSetter + fun Any.foo(a: Double = 0.0, v: String? = null) = "OK" +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNonNativeClassMembers.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNonNativeClassMembers.fir.kt new file mode 100644 index 00000000000..103643893ae --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalNonNativeClassMembers.fir.kt @@ -0,0 +1,45 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -NON_TOPLEVEL_CLASS_DECLARATION, -DEPRECATION + +fun foo() { + class A { + @nativeSetter + fun set(a: String, v: Any?): Any? = null + + @nativeSetter + fun put(a: Number, v: String) {} + + @nativeSetter + fun foo(a: Int, v: String) {} + } + + class B { + @nativeSetter + var foo = 0 + } + + class C { + @nativeSetter + fun Int.set(a: String, v: Int) {} + + @nativeSetter + fun Int.set2(a: Number, v: String?) = "OK" + + @nativeSetter + fun Int.set3(a: Double, v: String?) = "OK" + + @nativeSetter + fun 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: Int = 0, v: String) = "OK" + } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalOtherDeclarations.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalOtherDeclarations.fir.kt new file mode 100644 index 00000000000..43371701dfe --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onLocalOtherDeclarations.fir.kt @@ -0,0 +1,12 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -NON_TOPLEVEL_CLASS_DECLARATION, -DEPRECATION + +fun foo() { + @nativeSetter + fun toplevelFun(): Any = 0 + + @nativeSetter + val toplevelVal = 0 + + @nativeSetter + class Foo {} +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.fir.kt new file mode 100644 index 00000000000..17c27658ceb --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNativeClassMembers.fir.kt @@ -0,0 +1,71 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION + +external class A { + @nativeSetter + fun set(a: String, v: Any?): Any? = definedExternally + + @nativeSetter + fun put(a: Number, v: String) { definedExternally } + + @nativeSetter + fun foo(a: Int, v: String) { definedExternally } + + @nativeSetter + fun set4(a: Double, v: String): Any = definedExternally + + @nativeSetter + fun set5(a: Double, v: String): CharSequence = definedExternally + + companion object { + @nativeSetter + fun set(a: String, v: Any?): Any? = definedExternally + + @nativeSetter + fun put(a: Number, v: String) { definedExternally } + + @nativeSetter + fun foo(a: Int, v: String) { definedExternally } + + @nativeSetter + fun set4(a: Double, v: String): Any = definedExternally + + @nativeSetter + fun set5(a: Double, v: String): CharSequence = definedExternally + } +} + +external class B { + @nativeSetter + val foo: Int = definedExternally + + @nativeSetter + object Obj1 {} + + companion object { + @nativeSetter + val foo: Int = definedExternally + + @nativeSetter + object Obj2 {} + } +} + +external class C { + @nativeSetter + fun set6(a: Double, v: String): Number = definedExternally + + @nativeSetter + fun set(): Any? = definedExternally + + @nativeSetter + fun set(a: A): Any? = definedExternally + + @nativeSetter + fun set(a: String, v: Any, v2: Any) { definedExternally } + + @nativeSetter + fun set(a: A, v: Any?) { definedExternally } + + @nativeSetter + fun foo(a: Number, v: String = definedExternally): String = definedExternally +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.fir.kt new file mode 100644 index 00000000000..46eac5d32fb --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNativeClass.fir.kt @@ -0,0 +1,92 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION + +external class A { + class B { + class A { + @nativeSetter + fun set(a: String, v: Any?): Any? = definedExternally + + @nativeSetter + fun put(a: Number, v: String) { definedExternally } + + @nativeSetter + fun foo(a: Int, v: String) { definedExternally } + + @nativeSetter + fun set4(a: Double, v: String): Any = definedExternally + + @nativeSetter + fun set5(a: Double, v: String): CharSequence = definedExternally + + companion object { + @nativeSetter + fun set(a: String, v: Any?): Any? = definedExternally + + @nativeSetter + fun put(a: Number, v: String) { definedExternally } + + @nativeSetter + fun foo(a: Int, v: String) { definedExternally } + + @nativeSetter + fun set4(a: Double, v: String): Any = definedExternally + + @nativeSetter + fun set5(a: Double, v: String): CharSequence = definedExternally + } + } + + class B { + @nativeSetter + val foo: Int = definedExternally + + @nativeSetter + object Obj1 {} + + companion object { + @nativeSetter + val foo: Int = definedExternally + + @nativeSetter + object Obj2 {} + } + } + + class C { + @nativeSetter + fun set6(a: Double, v: String): Number = definedExternally + + @nativeSetter + fun set(): Any? = definedExternally + + @nativeSetter + fun set(a: A): Any? = definedExternally + + @nativeSetter + fun set(a: String, v: Any, v2: Any) { definedExternally } + + @nativeSetter + fun set(a: A, v: Any?) { definedExternally } + + @nativeSetter + fun foo(a: Double = definedExternally, v: String = definedExternally): String = definedExternally + } + + object obj { + @nativeSetter + fun set(): Any? = definedExternally + + @nativeSetter + fun set(a: A): Any? = definedExternally + + @nativeSetter + fun set(a: String, v: Any, v2: Any) { definedExternally } + + @nativeSetter + fun set(a: A, v: Any?) { definedExternally } + + @nativeSetter + fun foo(a: Int, v: String = definedExternally): String = definedExternally + } + } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNonNativeClass.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNonNativeClass.fir.kt new file mode 100644 index 00000000000..aeb26f2e389 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNestedDeclarationsInsideNonNativeClass.fir.kt @@ -0,0 +1,130 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -NON_TOPLEVEL_CLASS_DECLARATION, -DEPRECATION + +class A { + class B { + class A { + @nativeSetter + fun set(a: String, v: Any?): Any? = null + + @nativeSetter + fun put(a: Number, v: String) {} + + @nativeSetter + fun foo(a: Int, v: String) {} + + @nativeSetter + fun set4(a: Double, v: String): Any = 1 + + @nativeSetter + fun set5(a: Double, v: String): CharSequence = "OK" + + companion object { + @nativeSetter + fun set(a: String, v: Any?): Any? = null + + @nativeSetter + fun put(a: Number, v: String) {} + + @nativeSetter + fun foo(a: Int, v: String) {} + } + } + + class B { + @nativeSetter + val foo = 0 + + @nativeSetter + object Obj1 {} + + companion object { + @nativeSetter + val foo = 0 + + @nativeSetter + object Obj2 {} + } + } + + class C { + @nativeSetter + fun Int.set(a: String, v: Int) {} + + @nativeSetter + fun Int.set2(a: Number, v: String?) = "OK" + + @nativeSetter + fun Int.set3(a: Double, v: String?) = "OK" + + @nativeSetter + fun Int.set6(a: Double, v: String): Number = 1 + + @nativeSetter + fun set(): Any? = null + + @nativeSetter + fun set(a: A): Any? = null + + @nativeSetter + fun set(a: String, v: Any, v2: Any) {} + + @nativeSetter + fun set(a: A, v: Any?) {} + + @nativeSetter + fun foo(a: Double = 0.0, v: String = "str") = "OK" + } + + object obj { + @nativeSetter + fun Int.set(a: String, v: Int) {} + + @nativeSetter + fun Int.set2(a: Number, v: String?) = "OK" + + @nativeSetter + fun Int.set3(a: Double, v: String?) = "OK" + + @nativeSetter + fun set(): Any? = null + + @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: Int, v: String = "str") = "OK" + } + + val anonymous = object { + @nativeSetter + fun Int.set(a: String, v: Int) {} + + @nativeSetter + fun Int.set2(a: Number, v: String?) = "OK" + + @nativeSetter + fun Int.set3(a: Double, v: String?) = "OK" + + @nativeSetter + fun set(): Any? = null + + @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" + } + } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNonNativeClassMembers.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNonNativeClassMembers.fir.kt new file mode 100644 index 00000000000..526e3681148 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onNonNativeClassMembers.fir.kt @@ -0,0 +1,65 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION + +class A { + @nativeSetter + fun set(a: String, v: Any?): Any? = null + + @nativeSetter + fun put(a: Number, v: String) {} + + @nativeSetter + fun foo(a: Int, v: String) {} + + companion object { + @nativeSetter + fun set(a: String, v: Any?): Any? = null + + @nativeSetter + fun put(a: Number, v: String) {} + + @nativeSetter + fun foo(a: Int, v: String) {} + } +} + +class B { + @nativeSetter + val foo = 0 + + @nativeSetter + object Obj1 {} + + companion object { + @nativeSetter + val foo = 0 + + @nativeSetter + object Obj2 {} + } +} + +class C { + @nativeSetter + fun Int.set(a: String, v: Int) {} + + @nativeSetter + fun Int.set2(a: Number, v: String?) = "OK" + + @nativeSetter + fun Int.set3(a: Double, v: String?) = "OK" + + @nativeSetter + fun 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: String = "0.0", v: String) = "OK" +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelExtensionFun.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelExtensionFun.fir.kt new file mode 100644 index 00000000000..59f0cae5dac --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelExtensionFun.fir.kt @@ -0,0 +1,31 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION + +@nativeSetter +fun Int.set(a: String, v: Int) {} + +@nativeSetter +fun Int.set2(a: Number, v: String?): Any? = null + +@nativeSetter +fun Int.set3(a: Double, v: String) = "OK" + +@nativeSetter +fun Int.set4(a: Double, v: String): Any = 1 + +@nativeSetter +fun Int.set5(a: Double, v: String): CharSequence = "OK" + +@nativeSetter +fun Int.set6(a: Double, v: String): Number = 1 + +@nativeSetter +fun Any.foo(a: String = "0.0", v: String = "str") = "OK" + +@nativeSetter +fun Int.set(a: A): Int? = 1 + +@nativeSetter +fun Int.set2(): String? = "OK" + +@nativeSetter +fun Int.set3(a: Any, b: Int, c: Any?) {} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelOtherDeclarations.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelOtherDeclarations.fir.kt new file mode 100644 index 00000000000..f05807945ab --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelOtherDeclarations.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER, -DEPRECATION + +@nativeSetter +fun toplevelFun(): Any = 0 + +@nativeSetter +val toplevelVal = 0 + +@nativeSetter +class Foo {} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.fir.kt new file mode 100644 index 00000000000..1e5d8192432 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nested.fir.kt @@ -0,0 +1,41 @@ +object O + +class TopLevel { + external class A + + class B + + fun foo() = 23 + + external fun bar(): Int + + val x = "a" + + external val y: String + + val O.u: String get() = "O.u" +} + +external class TopLevelNative { + external class A + + class B + + fun foo(): Int = definedExternally + + external fun bar(): Int + + val x: String = definedExternally + + external val y: String +} + +fun topLevelFun() { + external class A + + class B + + fun foo() = 23 + + external fun bar(): Int +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nonAbstractMembersOfInterface.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nonAbstractMembersOfInterface.fir.kt new file mode 100644 index 00000000000..147e87e1dd4 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nonAbstractMembersOfInterface.fir.kt @@ -0,0 +1,21 @@ +external interface I { + fun foo(): Unit = definedExternally + + val a: Int? + get() = definedExternally + + var b: String? + get() = definedExternally + set(value) = definedExternally + + val c: Int + get() = definedExternally + + var d: String + get() = definedExternally + set(value) = definedExternally + + var e: dynamic + get() = definedExternally + set(value) = definedExternally +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.kt index 39aa437d7a6..e446c8a2d21 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/native.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNREACHABLE_CODE // unreachable code suppressed due to KT-9586 @@ -38,4 +39,4 @@ external object O { fun foo(s: String): String fun bar(s: String): String = definedExternally -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/nativeGetter.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/nativeGetter.fir.kt new file mode 100644 index 00000000000..1a8252eca47 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/nativeGetter.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -DEPRECATION +@nativeGetter +fun String.foo(n: Int): Int? +@nativeGetter +fun String.bar(n: Int): Int? = definedExternally + + +external interface T { + @nativeGetter + fun foo(d: Double): String? + @nativeGetter + fun bar(d: Double): String? +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/nativeInvoke.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/nativeInvoke.fir.kt new file mode 100644 index 00000000000..a267f489e18 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/nativeInvoke.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -DEPRECATION +@nativeInvoke +fun String.foo(): Int +@nativeInvoke +fun String.bar(): Int = definedExternally + + +external object O { + @nativeInvoke + fun foo() + @nativeInvoke + fun bar() { definedExternally } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/nativeSetter.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/nativeSetter.fir.kt new file mode 100644 index 00000000000..912b6e581ab --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/optionlBody/nativeSetter.fir.kt @@ -0,0 +1,13 @@ +// !DIAGNOSTICS: -DEPRECATION +@nativeSetter +fun String.foo(n: Int, v: Any) +@nativeSetter +fun String.bar(n: Int, v: Any) {} + + +external class C { + @nativeSetter + fun foo(d: Double, v: Any): Any + @nativeSetter + fun bar(d: Double, v: Any): Any = definedExternally +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/overrideOptionalParam.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/overrideOptionalParam.fir.kt new file mode 100644 index 00000000000..5fe95a5fae8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/overrideOptionalParam.fir.kt @@ -0,0 +1,60 @@ +open external class A { + open fun f(x: Int = definedExternally) +} + +class B : A() { + override fun f(x: Int) {} +} + +class BB : A() + +external class C : A { + override fun f(x: Int) +} + + +external interface I { + fun f(x: Int = definedExternally) +} + +interface J { + fun f(x: Int = 23) +} + +interface II { + fun f(x: Int) +} + +interface IIJ : II, J + +open external class D { + open fun f(x: Int) +} + +class E : D() { + override fun f(x: Int) { } +} + +class F : D(), I { + override fun f(x: Int) {} +} + +external class G : D, I { + override fun f(x: Int) +} + +open class X { + fun f(x: Int) {} +} + +open external class XE { + fun f(x: Int) +} + +class Y : X(), I + +class YY : A(), II + +external class YE: XE, I + +class Z : X(), J diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/privateMembers.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/privateMembers.fir.kt new file mode 100644 index 00000000000..d1547a2f9b3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/privateMembers.fir.kt @@ -0,0 +1,68 @@ +// !DIAGNOSTICS: -NOTHING_TO_INLINE +// TODO: should we disable NOTHING_TO_INLINE in JS backend? +// TODO: uncomment declarations in case we decide to implement KT-14031 + +external class C { + private fun a(): Int + + private val b: String + + private var c: Float + + private var d: Float + get + set + + var e: Float + get + private set + + /* + private inline fun inline_a(): Int = 23 + + private inline val inline_prop: Int + get() = 42 + */ +} + +external object O { + private fun a(): Int + + private val b: String + + private var c: Float + + private var d: Float + get + set + + /* + private inline fun inline_a(): Int = 23 + + private inline val inline_prop: Int + get() = 42 + */ +} + +external class Outer { + class Inner { + private fun a(): Int + + private val b: String + + private var c: Float + + private var d: Float + get + set + + /* + private inline fun inline_a(): Int = 23 + + private inline val inline_prop: Int + get() = 42 + */ + } + + private class PrivateInner +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/propertyParameter.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/propertyParameter.fir.kt new file mode 100644 index 00000000000..89f2958f218 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/propertyParameter.fir.kt @@ -0,0 +1 @@ +external class C(x: Int, val y: String) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/rtti/castToNativeInterface.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/rtti/castToNativeInterface.fir.kt new file mode 100644 index 00000000000..de0083de43b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/rtti/castToNativeInterface.fir.kt @@ -0,0 +1,5 @@ +external interface I + +fun box(a: Any, b: Any): Pair { + return Pair(a as I, b as? I) +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/rtti/checkForNativeInterface.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/rtti/checkForNativeInterface.fir.kt new file mode 100644 index 00000000000..ea5896b148f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/rtti/checkForNativeInterface.fir.kt @@ -0,0 +1,5 @@ +external interface I + +fun box(a: Any, b: Any): Boolean { + return a is I && b !is I +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/rtti/nativeInterfaceAsReifiedTypeArgument.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/rtti/nativeInterfaceAsReifiedTypeArgument.fir.kt new file mode 100644 index 00000000000..3635a691364 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/rtti/nativeInterfaceAsReifiedTypeArgument.fir.kt @@ -0,0 +1,21 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline fun foo(x: T) { + println(x) +} + +external interface I + +external class C : I + +operator inline fun C.plus(other: T) = this + +fun bar() { + foo(C()) + + val c: I = C() + foo(c) + foo(C()) + + C() + c +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/rtti/nativeInterfaceClassLiteral.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/rtti/nativeInterfaceClassLiteral.fir.kt new file mode 100644 index 00000000000..ed578687362 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/rtti/nativeInterfaceClassLiteral.fir.kt @@ -0,0 +1,5 @@ +external interface I + +fun box() { + println(I::class) +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/rtti/whenIsNativeInterface.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/rtti/whenIsNativeInterface.fir.kt new file mode 100644 index 00000000000..28462ebd76f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/rtti/whenIsNativeInterface.fir.kt @@ -0,0 +1,9 @@ +external interface I + +external interface J + +fun box(a: Any) = when (a) { + is I -> 0 + !is J -> 1 + else -> 2 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/native.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/native.kt index d58312c9f41..6621c364338 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/native.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/native.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL external fun foo(a: String): Int = definedExternally external class Bar(b: Int, c: Char) { @@ -9,4 +10,4 @@ external object Obj { object Nested { fun test2(g: Int) { definedExternally } } -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeGetter.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeGetter.kt index 5e3019e98f4..23ba1619d8d 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeGetter.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeGetter.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -DEPRECATION @nativeGetter fun Int.foo(a: String): Int? = definedExternally diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeInvoke.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeInvoke.kt index 6bede052d6f..fd211b70613 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeInvoke.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeInvoke.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -DEPRECATION @nativeInvoke fun Int.foo(a: String): Int = definedExternally diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeSetter.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeSetter.kt index 6b6bcbfe439..6266d8e0772 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeSetter.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/unusedParam/nativeSetter.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -DEPRECATION @nativeSetter fun Int.foo(a: String, v: Int): Int = definedExternally diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.fir.kt new file mode 100644 index 00000000000..f4fbf510832 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/wrongTarget.fir.kt @@ -0,0 +1,21 @@ +external annotation class A(val x: Int) + +val x: Int + external get() = definedExternally + +class B + +val B.x: Int + external get() = definedExternally + +class C { + val a: Int + external get() = definedExternally +} + +external class D { + val a: Int + external get() = definedExternally +} + +external data class E(val x: Int) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/noImpl.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/noImpl.fir.kt new file mode 100644 index 00000000000..8d0d6a6b33f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/noImpl.fir.kt @@ -0,0 +1,29 @@ +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER -UNUSED_PARAMETER, -UNREACHABLE_CODE + +val prop: String = definedExternally + +val prop2: String + get() = definedExternally + +fun foo(x: Int, y: String = definedExternally) { + println("Hello") + println("world") + + object { + fun bar(): Any = definedExternally + } + + listOf() + .map { definedExternally } + .filter(fun(x: String): Boolean { definedExternally }) + + definedExternally +} + +open class A(val x: Int) + +open class B() : A(definedExternally) { + constructor(y: String) : this() + + constructor(y: String, z: String) : this(y + z + definedExternally) +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/platformDependent.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/platformDependent.fir.kt new file mode 100644 index 00000000000..7a5381d24c7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/platformDependent.fir.kt @@ -0,0 +1,5 @@ +fun test(m: Map, mm: MutableMap) { + m.getOrDefault("2", 1) + mm.getOrDefault(1, "2") + mm.remove(1, "2") +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/qualifier/jsQualifierNonExternal.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/qualifier/jsQualifierNonExternal.fir.kt new file mode 100644 index 00000000000..ba10220fa13 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/qualifier/jsQualifierNonExternal.fir.kt @@ -0,0 +1,9 @@ +@file:JsQualifier("a.b") + +class A { + class B + + fun bar() {} +} + +fun foo() = "OK" diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/qualifier/wrongQualifier.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/qualifier/wrongQualifier.fir.kt new file mode 100644 index 00000000000..8e1a002a6ba --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/qualifier/wrongQualifier.fir.kt @@ -0,0 +1,17 @@ +// FILE: a.kt +@file:JsQualifier("") + +// FILE: b.kt +@file:JsQualifier("a..b") + +// FILE: c.kt +@file:JsQualifier("a.") + +// FILE: d.kt +@file:JsQualifier(".a") + +// FILE: e.kt +@file:JsQualifier("%^&") + +// FILE: f.kt +@file:JsQualifier("a.bc.d23._$") diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/reflection/reflectionApi.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/reflection/reflectionApi.fir.kt new file mode 100644 index 00000000000..9f83736cd35 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/reflection/reflectionApi.fir.kt @@ -0,0 +1,50 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION +import kotlin.reflect.* + +class Foo(val prop: Any) { + fun func() {} +} + +fun testSomeValidCases(p0: KProperty0, pm0: KMutableProperty0, f: KFunction, p1: KProperty1, p2: KProperty2) { + Foo::prop + Foo::func + Foo::class + p0.get() + p0.name + pm0.set("") + f.name + p1.get("") + p2.get("", "") + (Foo::func).invoke(Foo("")) + (Foo::func)(Foo("")) + + p0 == pm0 + p1.equals(p2) + p0.hashCode() + f.toString() +} + +fun kclass(k: KClass<*>, kt: KClass) { + k.simpleName + k.qualifiedName + k.members + k.constructors + k.nestedClasses + k.objectInstance + k.typeParameters + k.supertypes + k.visibility + k.isFinal + k.isOpen + k.isAbstract + k.isSealed + k.isData + k.isInner + k.isCompanion + + k.annotations + + k == kt + k.hashCode() + k.toString() +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/runtimeAnnotations.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/runtimeAnnotations.fir.kt new file mode 100644 index 00000000000..243dcf104a3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/runtimeAnnotations.fir.kt @@ -0,0 +1,59 @@ +@Retention(AnnotationRetention.BINARY) +annotation class X + +@Retention(AnnotationRetention.RUNTIME) +annotation class Y + +@X +external class A { + @X + fun f() + + @X + val p: Int + + @get:X + val r: Int +} + +@Y +external class B { + @Y + fun f() + + @Y + val p: Int + + @get:Y + val r: Int +} + +@X +class C { + @X + fun f() {} + + @X + val p: Int = 0 + + val q: Int + @X get() = 0 + + @get:X + val r: Int = 0 +} + +@Y +class D { + @Y + fun f() {} + + @Y + val p: Int = 0 + + val q: Int + @Y get() = 0 + + @get:Y + val r: Int = 0 +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/unsafeCastFunctionOnDynamicType.kt b/compiler/testData/diagnostics/testsWithJsStdLib/unsafeCastFunctionOnDynamicType.kt index 3f1be190d52..585f755535d 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/unsafeCastFunctionOnDynamicType.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/unsafeCastFunctionOnDynamicType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL fun String.toDouble(): Double = (+(this.asDynamic())).unsafeCast().also { if (it.isNaN() && !this.isNaN() || it == 0.0 && this.isBlank()) @@ -7,4 +8,4 @@ fun String.toDouble(): Double = (+(this.asDynamic())).unsafeCast().also fun String.isNaN(): Boolean = when (this.lowercase()) { "nan", "+nan", "-nan" -> true else -> false -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/wrongMultipleInheritance.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/wrongMultipleInheritance.fir.kt new file mode 100644 index 00000000000..4670c87b429 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/wrongMultipleInheritance.fir.kt @@ -0,0 +1,25 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class A { + fun get(index: Int): Char = '*' +} + +abstract class B : A(), CharSequence + +interface I { + fun nextChar(): Char +} + +abstract class C : CharIterator(), I { + override fun nextChar(): Char = '*' +} + +class CC(val s: CharSequence) : CharSequence by s, MyCharSequence {} + +interface MyCharSequence { + val length: Int + + operator fun get(index: Int): Char + + fun subSequence(startIndex: Int, endIndex: Int): CharSequence +}