KT-411 Wrong type expected when returning from a function literal

This commit is contained in:
svtk
2011-11-09 16:43:29 +04:00
parent 7c05e4b9b4
commit 0356bd98ec
13 changed files with 133 additions and 26 deletions
@@ -5,9 +5,11 @@ fun unitEmpty() : Unit {}
fun unitEmptyReturn() : Unit {return}
fun unitIntReturn() : Unit {return <!TYPE_MISMATCH!>1<!>}
fun unitUnitReturn() : Unit {return ()}
fun test1() : Any = {return}
fun test1() : Any = {<!RETURN_NOT_ALLOWED!>return<!>}
fun test2() : Any = @a {return@a 1}
fun test3() : Any { <!RETURN_TYPE_MISMATCH!>return<!> }
fun test4(): fun(): Unit = { <!RETURN_NOT_ALLOWED!>return@test4<!> }
fun test5(): Any = @{ return@ }
fun bbb() {
return <!TYPE_MISMATCH!>1<!>
@@ -6,12 +6,12 @@ class A {
if (1 < 2)
return@inner
else
return@outer
<!RETURN_NOT_ALLOWED!>return@outer<!>
}
if (1 < 2)
<!NOT_A_RETURN_LABEL!>return@A<!>
<!RETURN_NOT_ALLOWED!>return@A<!>
else if (2 < 3)
<!NOT_A_RETURN_LABEL!>return<!UNRESOLVED_REFERENCE!>@inner<!><!>
<!RETURN_NOT_ALLOWED!>return<!UNRESOLVED_REFERENCE!>@inner<!><!>
return@outer
}
}
}
@@ -0,0 +1,69 @@
//kt-411 Wrong type expected when returning from a function literal
namespace kt411
fun f() {
invoker(
@{
return@ 11 // expects Function, but should expect Int
}
)
}
fun invoker(gen : fun() : Int) : Int = 0
//more tests
fun t1() {
val v = @{ () : Int =>
return@ 111
}
}
fun t2() : String {
val g : fun(): Int = @{
if (true) {
return@ 1
}
<!RETURN_NOT_ALLOWED!>return <!TYPE_MISMATCH!>"s"<!><!>
}
return "s"
}
fun t3() : String {
invoker(
@{
if (true) {
<!RETURN_NOT_ALLOWED!>return@t3 <!TYPE_MISMATCH!>"1"<!><!>
}
else {
<!RETURN_NOT_ALLOWED!>return <!TYPE_MISMATCH!>"2"<!><!>
}
return@ 0
}
)
invoker(
@{ (): Int =>
return@ 1
}
)
invoker(
{
<!RETURN_NOT_ALLOWED!>return <!TYPE_MISMATCH!>"0"<!><!>
}
)
return "2"
}
fun t4() : Int {
val h : fun (): String = @l{
return@l "a"
}
val g : fun (): String = @{ () : String =>
return@ "a"
}
fun inner(): String {
return "2"
}
return 12
}