[tests] Added samples for compiler checks

This commit is contained in:
Igor Chevdar
2020-10-07 14:26:46 +05:00
parent 44358697f8
commit e7441037f6
56 changed files with 360 additions and 0 deletions
@@ -0,0 +1 @@
These tests aren't invoked so far because there is no mechanism of checking compilation errors yet.
+11
View File
@@ -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)
}
@@ -0,0 +1,7 @@
import kotlinx.cinterop.*
fun foo(f: Function1<*, Int>) = f
fun bar() {
staticCFunction(::foo)
}
@@ -0,0 +1,7 @@
import kotlinx.cinterop.*
fun foo(f: Function1<in Int, Int>) = f
fun bar() {
staticCFunction(::foo)
}
@@ -0,0 +1,7 @@
import kotlinx.cinterop.*
fun foo(x: CValue<*>?) = x
fun bar() {
staticCFunction(::foo)
}
@@ -0,0 +1,8 @@
import kotlinx.cinterop.*
fun <T: CVariable> bar() {
fun foo(x: CValue<T>) = x
staticCFunction(::foo)
}
@@ -0,0 +1,9 @@
import kotlinx.cinterop.*
class Z(rawPtr: NativePtr): CStructVar(rawPtr)
fun foo(x: CValue<Z>) = x
fun bar() {
staticCFunction(::foo)
}
@@ -0,0 +1,4 @@
import platform.darwin.*
import platform.Foundation.*
fun foo() = NSLog("zzz", {})
@@ -0,0 +1,6 @@
import platform.darwin.*
import platform.Foundation.*
class Z
fun foo() = NSLog("zzz", Z())
@@ -0,0 +1,8 @@
import platform.darwin.*
import platform.Foundation.*
class Foo : NSObject(), NSPortDelegateProtocol {
fun foo() {
super.handlePortMessage(TODO())
}
}
@@ -0,0 +1,9 @@
import platform.darwin.*
class Foo : NSObject() {
companion object : NSObjectMeta() {
fun bar() {
super.hash()
}
}
}
@@ -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?) { }
}
@@ -0,0 +1,4 @@
import platform.darwin.*
import platform.Foundation.*
interface Zzz : NSCopyingProtocolMeta
@@ -0,0 +1,4 @@
import platform.darwin.*
import platform.Foundation.*
open class Zzz : NSAssertionHandler()
@@ -0,0 +1,8 @@
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler() {
companion object {
val Z = 42
}
}
@@ -0,0 +1,6 @@
import platform.darwin.*
import platform.Foundation.*
interface I
class Zzz : NSAssertionHandler(), I
@@ -0,0 +1,4 @@
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSCopyingProtocolMeta
@@ -0,0 +1,6 @@
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler() {
override fun toString() = "zzz"
}
@@ -0,0 +1,8 @@
import kotlinx.cinterop.*
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler() {
@ObjCAction
fun String.foo() = println(this)
}
@@ -0,0 +1,8 @@
import kotlinx.cinterop.*
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler() {
@ObjCAction
fun foo(x: String) = println(x)
}
@@ -0,0 +1,8 @@
import kotlinx.cinterop.*
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler() {
@ObjCAction
fun foo() = 42
}
@@ -0,0 +1,8 @@
import kotlinx.cinterop.*
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler() {
@ObjCOutlet
val x: NSObject get() = this
}
@@ -0,0 +1,5 @@
import platform.posix.*
fun main() {
println(::printf)
}
@@ -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) { }
}
@@ -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) { }
}
@@ -0,0 +1,8 @@
import kotlinx.cinterop.*
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSAssertionHandler {
@OverrideInit
constructor(x: Int) { }
}
@@ -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"
}
@@ -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) { }
}
@@ -0,0 +1,5 @@
import kotlinx.cinterop.*
import platform.darwin.*
import platform.Foundation.*
class Zzz : NSValue()
@@ -0,0 +1,4 @@
import kotlinx.cinterop.*
import platform.posix.*
fun foo() = stat(malloc(42)!!.rawValue)
@@ -0,0 +1,11 @@
import kotlinx.cinterop.*
import kotlinx.cinterop.internal.*
@CStruct(spelling = "struct { }") class Z constructor(rawPtr: NativePtr) : CStructVar(rawPtr) {
val x: Pair<Int, Int>? = null
@CStruct.MemberAt(offset = 0L) get
}
fun foo(z: Z) = z.x
fun main() { }
@@ -0,0 +1,14 @@
import kotlinx.cinterop.*
import kotlinx.cinterop.internal.*
@CStruct(spelling = "struct { }") class Z constructor(rawPtr: NativePtr) : CStructVar(rawPtr) {
var x: Pair<Int, Int>? = null
@CStruct.MemberAt(offset = 0L) get
@CStruct.MemberAt(offset = 0L) set
}
fun foo(z: Z) {
z.x = 42 to 117
}
fun main() { }
@@ -0,0 +1,4 @@
import platform.darwin.*
import platform.Foundation.*
fun foo() = println(NSAssertionHandler()::handleFailureInFunction)
@@ -0,0 +1,9 @@
import kotlinx.cinterop.*
class Z {
fun foo(x: Int) = x
}
fun bar() {
staticCFunction(Z()::foo)
}
@@ -0,0 +1,8 @@
import kotlinx.cinterop.*
fun bar(x: Int) {
fun foo() = x
staticCFunction(::foo)
}
@@ -0,0 +1,7 @@
import kotlinx.cinterop.*
fun foo(x: Any) = x
fun bar() {
staticCFunction<String, Any>(::foo)
}
@@ -0,0 +1,3 @@
import kotlinx.cinterop.*
fun bar(x: Float) = x.signExtend<Int>()
@@ -0,0 +1,3 @@
import kotlinx.cinterop.*
fun bar(x: Int) = x.signExtend<Float>()
@@ -0,0 +1,3 @@
import kotlinx.cinterop.*
fun bar(x: Int) = x.signExtend<Short>()
@@ -0,0 +1,3 @@
import kotlinx.cinterop.*
fun bar(x: Int) = x.narrow<Long>()
@@ -0,0 +1,3 @@
import kotlinx.cinterop.*
fun bar(x: Int) = x.convert<String>()
@@ -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)
}
@@ -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() }
}
@@ -0,0 +1,4 @@
import platform.darwin.*
import platform.Foundation.*
fun foo() = NSAssertionHandler().handleFailureInFunction("zzz", "zzz", 0L, null, "qzz")
@@ -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)
}
}
@@ -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)
}
@@ -0,0 +1,6 @@
import kotlin.native.internal.*
@OptIn(kotlin.ExperimentalStdlibApi::class)
fun foo(x: Int) {
createCleaner(42) { println(x) }
}
@@ -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)
}
@@ -0,0 +1 @@
fun foo(arr: ShortArray) = immutableBlobOf(*arr)
@@ -0,0 +1 @@
fun foo(x: Short) = immutableBlobOf(x)
@@ -0,0 +1 @@
fun foo() = immutableBlobOf(1000)
@@ -0,0 +1 @@
fun foo() = immutableBlobOf()
@@ -0,0 +1,4 @@
import platform.darwin.*
import platform.Foundation.*
fun foo(s: Array<Any?>) = NSAssertionHandler().handleFailureInFunction("zzz", "zzz", 0L, null, *s)
@@ -0,0 +1,4 @@
import platform.darwin.*
import platform.Foundation.*
fun foo(s: Array<Any?>) = NSLog("zzz", *s)
@@ -0,0 +1,7 @@
import kotlinx.cinterop.*
fun foo(f: Function0<*>) = f
fun bar() {
staticCFunction(::foo)
}
@@ -0,0 +1,7 @@
import kotlinx.cinterop.*
fun foo(f: Function0<out Int>) = f
fun bar() {
staticCFunction(::foo)
}