Files
kotlin/compiler/testData/codegen/box/controlStructures/kt237.kt
Denis Zharkov 654411a0b0 Refactored tests using Array constructor:
Some moved to tests with stdlib
Some changed to use arrayOfNulls
2014-12-11 16:04:03 +03:00

42 lines
1.1 KiB
Kotlin

fun main(args: Array<String>?) {
val y: Unit = Unit //do not compile
A<Unit>() //do not compile
C<Unit>(Unit) //do not compile
//do not compile
System.out?.println(fff<Unit>(Unit)) //do not compile
System.out?.println(id<Unit>(y)) //do not compile
System.out?.println(fff<Unit>(id<Unit>(y)) == id<Unit>(foreach(arrayOfNulls<Int>(0) as Array<Int>,{(e : Int) : Unit -> }))) //do not compile
}
class A<T>()
class C<T>(val value: T) {
fun foo(): T = value
}
fun <T> fff(x: T) : T { return x }
fun <T> id(value: T): T = value
fun foreach(array: Array<Int>, action: (Int)-> Unit) {
for (el in array) {
action(el) //exception through compilation (see below)
}
}
fun almostFilter(array: Array<Int>, action: (Int)-> Int) {
for (el in array) {
action(el)
}
}
fun box() : String {
val a = arrayOfNulls<Int>(3) as Array<Int>
a[0] = 0
a[1] = 1
a[2] = 2
foreach(a, { (el : Int) : Unit -> System.out?.println(el) })
almostFilter(a, { (el : Int) : Int -> el })
main(null)
return "OK"
}