KT-352 Function variable declaration type isn't checked inside a function body

This commit is contained in:
svtk
2011-11-11 01:00:40 +04:00
parent 4a87566fa2
commit 3bfd7955a0
2 changed files with 99 additions and 54 deletions
@@ -0,0 +1,27 @@
//KT-352 Function variable declaration type isn't checked inside a function body
namespace kt352
val f : fun(Any) : Unit = <!TYPE_MISMATCH!>{ () : Unit => }<!> //type mismatch
fun foo() {
val f : fun(Any) : Unit = <!TYPE_MISMATCH!>{ () : Unit => }<!> //!!! no error
}
class A() {
val f : fun(Any) : Unit = <!TYPE_MISMATCH!>{ () : Unit => }<!> //type mismatch
}
//more tests
val g : fun() : Unit = <!TYPE_MISMATCH!>{ (): Int => 42 }<!>
val h : fun() : Unit = { doSmth() }
fun doSmth(): Int = 42
fun doSmth(a: String) {}
val testIt : fun(Any) : Unit = {
if (it is String) {
doSmth(it)
}
}