More fixes for possible coercion to unit of type of last statement in block

This commit is contained in:
svtk
2011-10-10 20:45:42 +04:00
parent fc6879e7fd
commit 868e024c93
4 changed files with 107 additions and 30 deletions
@@ -168,4 +168,42 @@ fun f(): Int = if (1 < 2) 1 else returnNothing()
public fun <!PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE!>f<!>() = 1
class B() {
protected fun <!PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE!>f<!>() = "ss"
}
fun testFunctionLiterals() {
val endsWithVarDeclaration : fun() : Boolean = {
<!EXPECTED_TYPE_MISMATCH!>val x = 2<!>
}
val endsWithAssignment = { () : Int =>
val x = 1
<!EXPECTED_TYPE_MISMATCH!>x = 333<!>
}
val endsWithReAssignment = { () : Int =>
val x = 1
<!EXPECTED_TYPE_MISMATCH!>x += 333<!>
}
val endsWithFunDeclaration : fun() : String = {
val x = 1
x = 333
<!EXPECTED_TYPE_MISMATCH!>fun meow() : Unit {}<!>
}
val endsWithObjectDeclaration : fun() : Int = {
val x = 1
x = 333
<!EXPECTED_TYPE_MISMATCH!>object A {}<!>
}
val expectedUnitReturnType1 = { () : Unit =>
val x = 1
}
val expectedUnitReturnType2 = { () : Unit =>
fun meow() : Unit {}
object A {}
}
}
+9 -1
View File
@@ -1,5 +1,9 @@
import java.util.ArrayList
fun launch(f : fun() : Unit) {
f()
}
fun box(): String {
val list = ArrayList<Int>()
val foo : fun() : Unit = {
@@ -7,10 +11,14 @@ fun box(): String {
}
foo()
launch({
list.add(3)
})
val bar = {
val x = 1 //second exception
}
bar()
return if (list.get(0) == 2) "OK" else "fail"
return if (list.size() == 2 && list.get(0) == 2 && list.get(1) == 3) "OK" else "fail"
}