KT-10717 Type inference for lambda with local return

#KT-10717 Fixed
This commit is contained in:
Stanislav Erokhin
2016-06-09 20:22:29 +03:00
parent da01e4a57c
commit 585dcbf1f3
9 changed files with 126 additions and 13 deletions
@@ -32,15 +32,15 @@ fun testReturnFromAnonFun() =
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>testReturn1<!>() =
run {
return if (true) <!IMPLICIT_CAST_TO_ANY!>42<!>
else <!IMPLICIT_CAST_TO_ANY!>println()<!>
return <!TYPE_MISMATCH!>if (true) <!IMPLICIT_CAST_TO_ANY!>42<!>
else <!IMPLICIT_CAST_TO_ANY!>println()<!><!>
}
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>testReturn2<!>() =
run {
return if (true) <!IMPLICIT_CAST_TO_ANY!>42<!>
return <!TYPE_MISMATCH!>if (true) <!IMPLICIT_CAST_TO_ANY!>42<!>
else if (true) <!IMPLICIT_CAST_TO_ANY!>42<!>
else <!IMPLICIT_CAST_TO_ANY!>println()<!>
else <!IMPLICIT_CAST_TO_ANY!>println()<!><!>
}
fun testUsage1() =
@@ -0,0 +1,47 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNREACHABLE_CODE -UNUSED_PARAMETER -RETURN_NOT_ALLOWED
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>test1<!>() = run {
return <!TYPE_MISMATCH(String; Nothing)!>"OK"<!>
}
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>test2<!>() = run {
fun local(): String {
return ""
}
return <!TYPE_MISMATCH(String; Nothing)!>""<!>
}
inline fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> = null!!
fun test3(a: List<String>, b: List<Int>) = a.map {
if (it.length == 3) return <!TYPE_MISMATCH(Nothing?; List<Int>)!>null<!>
if (it.length == 4) return <!TYPE_MISMATCH(String; List<Int>)!>""<!>
if (it.length == 4) return <!TYPE_MISMATCH(Int; List<Int>)!>5<!>
if (it.length == 4) return b
1
}
fun test4() = run {
fun test5() {
return
<!RETURN_TYPE_MISMATCH!>return@test4<!>
return <!RETURN_TYPE_MISMATCH!>return@test4<!>
return <!TYPE_MISMATCH!>fun() { return; return@test4 <!TYPE_MISMATCH!>""<!> }<!>
}
<!RETURN_TYPE_MISMATCH!>return<!>
3
}
val foo: Int
get() = run {
if (true) return <!TYPE_MISMATCH!>""<!>
<!RETURN_TYPE_MISMATCH!>return<!>
}
fun test(): Int = run {
return <!TYPE_MISMATCH!>""<!>
}
@@ -0,0 +1,9 @@
package
public val foo: kotlin.Int
public fun test(): kotlin.Int
public fun test1(): kotlin.Nothing
public fun test2(): kotlin.Nothing
public fun test3(/*0*/ a: kotlin.collections.List<kotlin.String>, /*1*/ b: kotlin.collections.List<kotlin.Int>): kotlin.collections.List<kotlin.Int>
public fun test4(): kotlin.Int
public inline fun </*0*/ T, /*1*/ R> kotlin.collections.Iterable<T>.map(/*0*/ transform: (T) -> R): kotlin.collections.List<R>
@@ -26,22 +26,22 @@ fun testResultOfLambda2() =
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>testReturn1<!>() =
run {
return when {
return <!TYPE_MISMATCH!>when {
true -> <!IMPLICIT_CAST_TO_ANY!>42<!>
else -> <!IMPLICIT_CAST_TO_ANY!>println()<!>
}
}<!>
}
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>testReturn2<!>() =
run {
return when {
return <!TYPE_MISMATCH!>when {
true -> <!IMPLICIT_CAST_TO_ANY!>42<!>
else ->
when {
true -> <!IMPLICIT_CAST_TO_ANY!>42<!>
else -> <!IMPLICIT_CAST_TO_ANY!>println()<!>
}
}
}<!>
}
fun testUsage1() =