diff --git a/backend.native/tests/compilerChecks/README.md b/backend.native/tests/compilerChecks/README.md new file mode 100644 index 00000000000..d75d95ab9ee --- /dev/null +++ b/backend.native/tests/compilerChecks/README.md @@ -0,0 +1 @@ +These tests aren't invoked so far because there is no mechanism of checking compilation errors yet. \ No newline at end of file diff --git a/backend.native/tests/compilerChecks/t1.kt b/backend.native/tests/compilerChecks/t1.kt new file mode 100644 index 00000000000..e81a3254c87 --- /dev/null +++ b/backend.native/tests/compilerChecks/t1.kt @@ -0,0 +1,11 @@ +import kotlinx.cinterop.* + +fun foo(x: Int, vararg s: String): Int { + var sum = x + s.forEach { sum += it.length } + return sum +} + +fun bar() { + staticCFunction(::foo) +} diff --git a/backend.native/tests/compilerChecks/t10.kt b/backend.native/tests/compilerChecks/t10.kt new file mode 100644 index 00000000000..fbbbba0954a --- /dev/null +++ b/backend.native/tests/compilerChecks/t10.kt @@ -0,0 +1,7 @@ +import kotlinx.cinterop.* + +fun foo(f: Function1<*, Int>) = f + +fun bar() { + staticCFunction(::foo) +} diff --git a/backend.native/tests/compilerChecks/t11.kt b/backend.native/tests/compilerChecks/t11.kt new file mode 100644 index 00000000000..707553a0c4b --- /dev/null +++ b/backend.native/tests/compilerChecks/t11.kt @@ -0,0 +1,7 @@ +import kotlinx.cinterop.* + +fun foo(f: Function1) = f + +fun bar() { + staticCFunction(::foo) +} diff --git a/backend.native/tests/compilerChecks/t12.kt b/backend.native/tests/compilerChecks/t12.kt new file mode 100644 index 00000000000..b904dae2d67 --- /dev/null +++ b/backend.native/tests/compilerChecks/t12.kt @@ -0,0 +1,7 @@ +import kotlinx.cinterop.* + +fun foo(x: CValue<*>?) = x + +fun bar() { + staticCFunction(::foo) +} diff --git a/backend.native/tests/compilerChecks/t13.kt b/backend.native/tests/compilerChecks/t13.kt new file mode 100644 index 00000000000..0874088c4c9 --- /dev/null +++ b/backend.native/tests/compilerChecks/t13.kt @@ -0,0 +1,8 @@ +import kotlinx.cinterop.* + +fun bar() { + + fun foo(x: CValue) = x + + staticCFunction(::foo) +} diff --git a/backend.native/tests/compilerChecks/t14.kt b/backend.native/tests/compilerChecks/t14.kt new file mode 100644 index 00000000000..05f27179537 --- /dev/null +++ b/backend.native/tests/compilerChecks/t14.kt @@ -0,0 +1,9 @@ +import kotlinx.cinterop.* + +class Z(rawPtr: NativePtr): CStructVar(rawPtr) + +fun foo(x: CValue) = x + +fun bar() { + staticCFunction(::foo) +} diff --git a/backend.native/tests/compilerChecks/t15.kt b/backend.native/tests/compilerChecks/t15.kt new file mode 100644 index 00000000000..8f9b60dd74b --- /dev/null +++ b/backend.native/tests/compilerChecks/t15.kt @@ -0,0 +1,4 @@ +import platform.darwin.* +import platform.Foundation.* + +fun foo() = NSLog("zzz", {}) diff --git a/backend.native/tests/compilerChecks/t16.kt b/backend.native/tests/compilerChecks/t16.kt new file mode 100644 index 00000000000..69e31415fe1 --- /dev/null +++ b/backend.native/tests/compilerChecks/t16.kt @@ -0,0 +1,6 @@ +import platform.darwin.* +import platform.Foundation.* + +class Z + +fun foo() = NSLog("zzz", Z()) diff --git a/backend.native/tests/compilerChecks/t17.kt b/backend.native/tests/compilerChecks/t17.kt new file mode 100644 index 00000000000..fce3da8a57c --- /dev/null +++ b/backend.native/tests/compilerChecks/t17.kt @@ -0,0 +1,8 @@ +import platform.darwin.* +import platform.Foundation.* + +class Foo : NSObject(), NSPortDelegateProtocol { + fun foo() { + super.handlePortMessage(TODO()) + } +} diff --git a/backend.native/tests/compilerChecks/t18.kt b/backend.native/tests/compilerChecks/t18.kt new file mode 100644 index 00000000000..6ca701a7d4b --- /dev/null +++ b/backend.native/tests/compilerChecks/t18.kt @@ -0,0 +1,9 @@ +import platform.darwin.* + +class Foo : NSObject() { + companion object : NSObjectMeta() { + fun bar() { + super.hash() + } + } +} diff --git a/backend.native/tests/compilerChecks/t2.kt b/backend.native/tests/compilerChecks/t2.kt new file mode 100644 index 00000000000..03be45bb590 --- /dev/null +++ b/backend.native/tests/compilerChecks/t2.kt @@ -0,0 +1,6 @@ +import platform.darwin.* +import platform.Foundation.* + +class Zzz : NSAssertionHandler() { + override fun handleFailureInFunction(functionName: String, file: String, lineNumber: NSInteger /* = Long */, description: String?, vararg args: Any?) { } +} diff --git a/backend.native/tests/compilerChecks/t20.kt b/backend.native/tests/compilerChecks/t20.kt new file mode 100644 index 00000000000..50e2de5cc32 --- /dev/null +++ b/backend.native/tests/compilerChecks/t20.kt @@ -0,0 +1,4 @@ +import platform.darwin.* +import platform.Foundation.* + +interface Zzz : NSCopyingProtocolMeta diff --git a/backend.native/tests/compilerChecks/t21.kt b/backend.native/tests/compilerChecks/t21.kt new file mode 100644 index 00000000000..6a0f459b8d5 --- /dev/null +++ b/backend.native/tests/compilerChecks/t21.kt @@ -0,0 +1,4 @@ +import platform.darwin.* +import platform.Foundation.* + +open class Zzz : NSAssertionHandler() diff --git a/backend.native/tests/compilerChecks/t22.kt b/backend.native/tests/compilerChecks/t22.kt new file mode 100644 index 00000000000..a095f936c1a --- /dev/null +++ b/backend.native/tests/compilerChecks/t22.kt @@ -0,0 +1,8 @@ +import platform.darwin.* +import platform.Foundation.* + +class Zzz : NSAssertionHandler() { + companion object { + val Z = 42 + } +} diff --git a/backend.native/tests/compilerChecks/t23.kt b/backend.native/tests/compilerChecks/t23.kt new file mode 100644 index 00000000000..e4d06a2efe8 --- /dev/null +++ b/backend.native/tests/compilerChecks/t23.kt @@ -0,0 +1,6 @@ +import platform.darwin.* +import platform.Foundation.* + +interface I + +class Zzz : NSAssertionHandler(), I diff --git a/backend.native/tests/compilerChecks/t24.kt b/backend.native/tests/compilerChecks/t24.kt new file mode 100644 index 00000000000..1e996546be2 --- /dev/null +++ b/backend.native/tests/compilerChecks/t24.kt @@ -0,0 +1,4 @@ +import platform.darwin.* +import platform.Foundation.* + +class Zzz : NSCopyingProtocolMeta diff --git a/backend.native/tests/compilerChecks/t25.kt b/backend.native/tests/compilerChecks/t25.kt new file mode 100644 index 00000000000..b57b8fabeb4 --- /dev/null +++ b/backend.native/tests/compilerChecks/t25.kt @@ -0,0 +1,6 @@ +import platform.darwin.* +import platform.Foundation.* + +class Zzz : NSAssertionHandler() { + override fun toString() = "zzz" +} diff --git a/backend.native/tests/compilerChecks/t26.kt b/backend.native/tests/compilerChecks/t26.kt new file mode 100644 index 00000000000..dd79c6bff10 --- /dev/null +++ b/backend.native/tests/compilerChecks/t26.kt @@ -0,0 +1,8 @@ +import kotlinx.cinterop.* +import platform.darwin.* +import platform.Foundation.* + +class Zzz : NSAssertionHandler() { + @ObjCAction + fun String.foo() = println(this) +} diff --git a/backend.native/tests/compilerChecks/t27.kt b/backend.native/tests/compilerChecks/t27.kt new file mode 100644 index 00000000000..ca088a337b2 --- /dev/null +++ b/backend.native/tests/compilerChecks/t27.kt @@ -0,0 +1,8 @@ +import kotlinx.cinterop.* +import platform.darwin.* +import platform.Foundation.* + +class Zzz : NSAssertionHandler() { + @ObjCAction + fun foo(x: String) = println(x) +} diff --git a/backend.native/tests/compilerChecks/t28.kt b/backend.native/tests/compilerChecks/t28.kt new file mode 100644 index 00000000000..70de49cc2c6 --- /dev/null +++ b/backend.native/tests/compilerChecks/t28.kt @@ -0,0 +1,8 @@ +import kotlinx.cinterop.* +import platform.darwin.* +import platform.Foundation.* + +class Zzz : NSAssertionHandler() { + @ObjCAction + fun foo() = 42 +} diff --git a/backend.native/tests/compilerChecks/t29.kt b/backend.native/tests/compilerChecks/t29.kt new file mode 100644 index 00000000000..99600ea848d --- /dev/null +++ b/backend.native/tests/compilerChecks/t29.kt @@ -0,0 +1,8 @@ +import kotlinx.cinterop.* +import platform.darwin.* +import platform.Foundation.* + +class Zzz : NSAssertionHandler() { + @ObjCOutlet + val x: NSObject get() = this +} diff --git a/backend.native/tests/compilerChecks/t3.kt b/backend.native/tests/compilerChecks/t3.kt new file mode 100644 index 00000000000..990b6549265 --- /dev/null +++ b/backend.native/tests/compilerChecks/t3.kt @@ -0,0 +1,5 @@ +import platform.posix.* + +fun main() { + println(::printf) +} diff --git a/backend.native/tests/compilerChecks/t30.kt b/backend.native/tests/compilerChecks/t30.kt new file mode 100644 index 00000000000..c7726d491ed --- /dev/null +++ b/backend.native/tests/compilerChecks/t30.kt @@ -0,0 +1,10 @@ +import kotlinx.cinterop.* +import platform.darwin.* +import platform.Foundation.* + +class Zzz : NSAssertionHandler() { + @ObjCOutlet + var NSObject.x: NSObject + get() = this + set(value: NSObject) { } +} diff --git a/backend.native/tests/compilerChecks/t31.kt b/backend.native/tests/compilerChecks/t31.kt new file mode 100644 index 00000000000..df6b62782a9 --- /dev/null +++ b/backend.native/tests/compilerChecks/t31.kt @@ -0,0 +1,10 @@ +import kotlinx.cinterop.* +import platform.darwin.* +import platform.Foundation.* + +class Zzz : NSAssertionHandler() { + @ObjCOutlet + var x: String + get() = "zzz" + set(value: String) { } +} diff --git a/backend.native/tests/compilerChecks/t32.kt b/backend.native/tests/compilerChecks/t32.kt new file mode 100644 index 00000000000..60be6649f8d --- /dev/null +++ b/backend.native/tests/compilerChecks/t32.kt @@ -0,0 +1,8 @@ +import kotlinx.cinterop.* +import platform.darwin.* +import platform.Foundation.* + +class Zzz : NSAssertionHandler { + @OverrideInit + constructor(x: Int) { } +} diff --git a/backend.native/tests/compilerChecks/t33.kt b/backend.native/tests/compilerChecks/t33.kt new file mode 100644 index 00000000000..a628b0bd1a9 --- /dev/null +++ b/backend.native/tests/compilerChecks/t33.kt @@ -0,0 +1,10 @@ +import kotlinx.cinterop.* +import platform.darwin.* +import platform.Foundation.* + +class Zzz : NSString { + @OverrideInit + constructor(coder: NSCoder) { } + + override fun initWithCoder(coder: NSCoder): String? = "zzz" +} diff --git a/backend.native/tests/compilerChecks/t34.kt b/backend.native/tests/compilerChecks/t34.kt new file mode 100644 index 00000000000..bca42e1ec95 --- /dev/null +++ b/backend.native/tests/compilerChecks/t34.kt @@ -0,0 +1,8 @@ +import kotlinx.cinterop.* +import platform.darwin.* +import platform.Foundation.* + +class Zzz : NSAssertionHandler() { + @ObjCAction + fun foo(x: NSObject, y: NSObject, z: NSObject) { } +} diff --git a/backend.native/tests/compilerChecks/t35.kt b/backend.native/tests/compilerChecks/t35.kt new file mode 100644 index 00000000000..8af8740565a --- /dev/null +++ b/backend.native/tests/compilerChecks/t35.kt @@ -0,0 +1,5 @@ +import kotlinx.cinterop.* +import platform.darwin.* +import platform.Foundation.* + +class Zzz : NSValue() diff --git a/backend.native/tests/compilerChecks/t36.kt b/backend.native/tests/compilerChecks/t36.kt new file mode 100644 index 00000000000..2b71817f750 --- /dev/null +++ b/backend.native/tests/compilerChecks/t36.kt @@ -0,0 +1,4 @@ +import kotlinx.cinterop.* +import platform.posix.* + +fun foo() = stat(malloc(42)!!.rawValue) diff --git a/backend.native/tests/compilerChecks/t37.kt b/backend.native/tests/compilerChecks/t37.kt new file mode 100644 index 00000000000..be41239bc02 --- /dev/null +++ b/backend.native/tests/compilerChecks/t37.kt @@ -0,0 +1,11 @@ +import kotlinx.cinterop.* +import kotlinx.cinterop.internal.* + +@CStruct(spelling = "struct { }") class Z constructor(rawPtr: NativePtr) : CStructVar(rawPtr) { + val x: Pair? = null + @CStruct.MemberAt(offset = 0L) get +} + +fun foo(z: Z) = z.x + +fun main() { } diff --git a/backend.native/tests/compilerChecks/t38.kt b/backend.native/tests/compilerChecks/t38.kt new file mode 100644 index 00000000000..893994fde2d --- /dev/null +++ b/backend.native/tests/compilerChecks/t38.kt @@ -0,0 +1,14 @@ +import kotlinx.cinterop.* +import kotlinx.cinterop.internal.* + +@CStruct(spelling = "struct { }") class Z constructor(rawPtr: NativePtr) : CStructVar(rawPtr) { + var x: Pair? = null + @CStruct.MemberAt(offset = 0L) get + @CStruct.MemberAt(offset = 0L) set +} + +fun foo(z: Z) { + z.x = 42 to 117 +} + +fun main() { } diff --git a/backend.native/tests/compilerChecks/t4.kt b/backend.native/tests/compilerChecks/t4.kt new file mode 100644 index 00000000000..221d7844690 --- /dev/null +++ b/backend.native/tests/compilerChecks/t4.kt @@ -0,0 +1,4 @@ +import platform.darwin.* +import platform.Foundation.* + +fun foo() = println(NSAssertionHandler()::handleFailureInFunction) diff --git a/backend.native/tests/compilerChecks/t40.kt b/backend.native/tests/compilerChecks/t40.kt new file mode 100644 index 00000000000..4dfde08192e --- /dev/null +++ b/backend.native/tests/compilerChecks/t40.kt @@ -0,0 +1,9 @@ +import kotlinx.cinterop.* + +class Z { + fun foo(x: Int) = x +} + +fun bar() { + staticCFunction(Z()::foo) +} diff --git a/backend.native/tests/compilerChecks/t41.kt b/backend.native/tests/compilerChecks/t41.kt new file mode 100644 index 00000000000..e50949ca4d3 --- /dev/null +++ b/backend.native/tests/compilerChecks/t41.kt @@ -0,0 +1,8 @@ +import kotlinx.cinterop.* + +fun bar(x: Int) { + + fun foo() = x + + staticCFunction(::foo) +} diff --git a/backend.native/tests/compilerChecks/t42.kt b/backend.native/tests/compilerChecks/t42.kt new file mode 100644 index 00000000000..8f409411fb9 --- /dev/null +++ b/backend.native/tests/compilerChecks/t42.kt @@ -0,0 +1,7 @@ +import kotlinx.cinterop.* + +fun foo(x: Any) = x + +fun bar() { + staticCFunction(::foo) +} diff --git a/backend.native/tests/compilerChecks/t43.kt b/backend.native/tests/compilerChecks/t43.kt new file mode 100644 index 00000000000..b30ae793fd1 --- /dev/null +++ b/backend.native/tests/compilerChecks/t43.kt @@ -0,0 +1,3 @@ +import kotlinx.cinterop.* + +fun bar(x: Float) = x.signExtend() diff --git a/backend.native/tests/compilerChecks/t44.kt b/backend.native/tests/compilerChecks/t44.kt new file mode 100644 index 00000000000..069546b5c34 --- /dev/null +++ b/backend.native/tests/compilerChecks/t44.kt @@ -0,0 +1,3 @@ +import kotlinx.cinterop.* + +fun bar(x: Int) = x.signExtend() diff --git a/backend.native/tests/compilerChecks/t45.kt b/backend.native/tests/compilerChecks/t45.kt new file mode 100644 index 00000000000..19c83ebf6d5 --- /dev/null +++ b/backend.native/tests/compilerChecks/t45.kt @@ -0,0 +1,3 @@ +import kotlinx.cinterop.* + +fun bar(x: Int) = x.signExtend() diff --git a/backend.native/tests/compilerChecks/t46.kt b/backend.native/tests/compilerChecks/t46.kt new file mode 100644 index 00000000000..3b4e7ab349a --- /dev/null +++ b/backend.native/tests/compilerChecks/t46.kt @@ -0,0 +1,3 @@ +import kotlinx.cinterop.* + +fun bar(x: Int) = x.narrow() diff --git a/backend.native/tests/compilerChecks/t47.kt b/backend.native/tests/compilerChecks/t47.kt new file mode 100644 index 00000000000..63ce4ea0c23 --- /dev/null +++ b/backend.native/tests/compilerChecks/t47.kt @@ -0,0 +1,3 @@ +import kotlinx.cinterop.* + +fun bar(x: Int) = x.convert() diff --git a/backend.native/tests/compilerChecks/t48.kt b/backend.native/tests/compilerChecks/t48.kt new file mode 100644 index 00000000000..5ae065ceebf --- /dev/null +++ b/backend.native/tests/compilerChecks/t48.kt @@ -0,0 +1,10 @@ +import kotlin.native.concurrent.* + +class Z(val x: Int) { + fun bar(s: String) = s + x.toString() +} + +fun foo(x: Int) { + val worker = Worker.start() + worker.execute(TransferMode.SAFE, { "zzz" }, Z(x)::bar) +} diff --git a/backend.native/tests/compilerChecks/t49.kt b/backend.native/tests/compilerChecks/t49.kt new file mode 100644 index 00000000000..2188c38b023 --- /dev/null +++ b/backend.native/tests/compilerChecks/t49.kt @@ -0,0 +1,6 @@ +import kotlin.native.concurrent.* + +fun foo(x: Int) { + val worker = Worker.start() + worker.execute(TransferMode.SAFE, { "zzz" }) { s -> s + x.toString() } +} diff --git a/backend.native/tests/compilerChecks/t5.kt b/backend.native/tests/compilerChecks/t5.kt new file mode 100644 index 00000000000..0b6fa0bbc49 --- /dev/null +++ b/backend.native/tests/compilerChecks/t5.kt @@ -0,0 +1,4 @@ +import platform.darwin.* +import platform.Foundation.* + +fun foo() = NSAssertionHandler().handleFailureInFunction("zzz", "zzz", 0L, null, "qzz") diff --git a/backend.native/tests/compilerChecks/t50.kt b/backend.native/tests/compilerChecks/t50.kt new file mode 100644 index 00000000000..41d5868c00a --- /dev/null +++ b/backend.native/tests/compilerChecks/t50.kt @@ -0,0 +1,13 @@ +import kotlin.native.concurrent.* + +class Z(val x: Int) { + fun bar(s: String) = s + x.toString() +} + +class Q(x: Int) { + init { + val worker = Worker.start() + worker.execute(TransferMode.SAFE, { "zzz" }, Z(x)::bar) + } +} + diff --git a/backend.native/tests/compilerChecks/t51.kt b/backend.native/tests/compilerChecks/t51.kt new file mode 100644 index 00000000000..5d3baa4a347 --- /dev/null +++ b/backend.native/tests/compilerChecks/t51.kt @@ -0,0 +1,10 @@ +import kotlin.native.concurrent.* + +class Z(val x: Int) { + fun bar(s: String) = s + x.toString() +} + +class Q(x: Int) { + val z = Worker.start().execute(TransferMode.SAFE, { "zzz" }, Z(x)::bar) +} + diff --git a/backend.native/tests/compilerChecks/t52.kt b/backend.native/tests/compilerChecks/t52.kt new file mode 100644 index 00000000000..1372cc106c5 --- /dev/null +++ b/backend.native/tests/compilerChecks/t52.kt @@ -0,0 +1,6 @@ +import kotlin.native.internal.* + +@OptIn(kotlin.ExperimentalStdlibApi::class) +fun foo(x: Int) { + createCleaner(42) { println(x) } +} diff --git a/backend.native/tests/compilerChecks/t53.kt b/backend.native/tests/compilerChecks/t53.kt new file mode 100644 index 00000000000..117948147b3 --- /dev/null +++ b/backend.native/tests/compilerChecks/t53.kt @@ -0,0 +1,10 @@ +import kotlin.native.internal.* + +class C(val x: Int) { + fun bar(y: Int) = println(x + y) +} + +@OptIn(kotlin.ExperimentalStdlibApi::class) +fun foo(x: Int) { + createCleaner(42, C(x)::bar) +} diff --git a/backend.native/tests/compilerChecks/t54.kt b/backend.native/tests/compilerChecks/t54.kt new file mode 100644 index 00000000000..fe3d45cd7b3 --- /dev/null +++ b/backend.native/tests/compilerChecks/t54.kt @@ -0,0 +1 @@ +fun foo(arr: ShortArray) = immutableBlobOf(*arr) diff --git a/backend.native/tests/compilerChecks/t55.kt b/backend.native/tests/compilerChecks/t55.kt new file mode 100644 index 00000000000..561fa724bf8 --- /dev/null +++ b/backend.native/tests/compilerChecks/t55.kt @@ -0,0 +1 @@ +fun foo(x: Short) = immutableBlobOf(x) diff --git a/backend.native/tests/compilerChecks/t56.kt b/backend.native/tests/compilerChecks/t56.kt new file mode 100644 index 00000000000..d286a28d7be --- /dev/null +++ b/backend.native/tests/compilerChecks/t56.kt @@ -0,0 +1 @@ +fun foo() = immutableBlobOf(1000) diff --git a/backend.native/tests/compilerChecks/t57.kt b/backend.native/tests/compilerChecks/t57.kt new file mode 100644 index 00000000000..d947c4e05c9 --- /dev/null +++ b/backend.native/tests/compilerChecks/t57.kt @@ -0,0 +1 @@ +fun foo() = immutableBlobOf() diff --git a/backend.native/tests/compilerChecks/t6.kt b/backend.native/tests/compilerChecks/t6.kt new file mode 100644 index 00000000000..ea60cfb3c3e --- /dev/null +++ b/backend.native/tests/compilerChecks/t6.kt @@ -0,0 +1,4 @@ +import platform.darwin.* +import platform.Foundation.* + +fun foo(s: Array) = NSAssertionHandler().handleFailureInFunction("zzz", "zzz", 0L, null, *s) diff --git a/backend.native/tests/compilerChecks/t7.kt b/backend.native/tests/compilerChecks/t7.kt new file mode 100644 index 00000000000..1b85b8f3a31 --- /dev/null +++ b/backend.native/tests/compilerChecks/t7.kt @@ -0,0 +1,4 @@ +import platform.darwin.* +import platform.Foundation.* + +fun foo(s: Array) = NSLog("zzz", *s) diff --git a/backend.native/tests/compilerChecks/t8.kt b/backend.native/tests/compilerChecks/t8.kt new file mode 100644 index 00000000000..91280d2d9ca --- /dev/null +++ b/backend.native/tests/compilerChecks/t8.kt @@ -0,0 +1,7 @@ +import kotlinx.cinterop.* + +fun foo(f: Function0<*>) = f + +fun bar() { + staticCFunction(::foo) +} diff --git a/backend.native/tests/compilerChecks/t9.kt b/backend.native/tests/compilerChecks/t9.kt new file mode 100644 index 00000000000..f65f2ebe230 --- /dev/null +++ b/backend.native/tests/compilerChecks/t9.kt @@ -0,0 +1,7 @@ +import kotlinx.cinterop.* + +fun foo(f: Function0) = f + +fun bar() { + staticCFunction(::foo) +}