fix for KT-237. Unit as value part

This commit is contained in:
Alex Tkachman
2011-09-04 16:27:54 +02:00
parent 22e2caf7f8
commit 58765f2364
5 changed files with 70 additions and 10 deletions
+24 -3
View File
@@ -1,20 +1,41 @@
fun foreach(array: Array<Int>, action: fun(Int): Unit) {
fun main(args: Array<String>?) {
val y: Unit = () //do not compile
A<Unit>() //do not compile
C<Unit>(()) //do not compile
//do not compile
System.out?.println(fff<Unit>(())) //do not compile
System.out?.println(id<Unit>(y)) //do not compile
System.out?.println(fff<Unit>(id<Unit>(y)) == id<Unit>(foreach(Array<Int>(0),{(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: fun(Int): Unit) {
for (el in array) {
action(el) //exception through compilation (see below)
}
}
/*
fun almostFilter(array: Array<Int>, action: fun(Int): Int) {
for (el in array) {
action(el)
}
}
*/
fun box() : String {
val a = Array<Int> (3)
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"
}