[NI] Fix coercion to Unit for lambdas with empty labeled return

This commit is contained in:
Mikhail Zarechenskiy
2019-01-29 15:37:27 +03:00
parent 147d7844bc
commit 6705803d83
7 changed files with 136 additions and 2 deletions
@@ -0,0 +1,42 @@
// !LANGUAGE: +NewInference
class Obj
fun foo(): String? {
run {
if (true) return@run
if (true) Obj()
}
run {
if (true) return@run
if (true) return <!TYPE_MISMATCH, TYPE_MISMATCH!>Obj()<!> // correct error, type check against return type of function "foo"
}
run {
if (true)
return@run
else
if (true) <!UNUSED_EXPRESSION!>42<!>
}
run {
if (true)
42
else
<!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
}
run {
if (true) return@run
if (true) {
Obj()
} else
if (true) return null
}
return ""
}
@@ -0,0 +1,10 @@
package
public fun foo(): kotlin.String?
public final class Obj {
public constructor Obj()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,52 @@
// !LANGUAGE: +NewInference
class Obj
fun foo(): String? {
run {
if (true) return@run
run {
if (true) {
Obj()
} else
<!INVALID_IF_AS_EXPRESSION!>if<!> (true) return null // Error, coercion to Unit doesn't propagate inside nested lambdas
}
if (true) {
Obj()
} else
if (true) return null // OK, no error
}
run {
if (true) return@run
run {
if (true) {
Obj()
} else
<!INVALID_IF_AS_EXPRESSION!>if<!> (true) return null // Error, coercion to Unit doesn't propagate inside nested lambdas
}
}
run {
if (true) return@run
run nestedRun@{
if (true) return@nestedRun
if (true) {
Obj()
} else
if (true) return null // OK, additional empty labeled return helps
}
if (true) {
Obj()
} else
if (true) return null // OK, no error
}
return ""
}
@@ -0,0 +1,10 @@
package
public fun foo(): kotlin.String?
public final class Obj {
public constructor Obj()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}