[NI] Fix coercion to Unit for lambdas with empty labeled return
This commit is contained in:
+42
@@ -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 ""
|
||||
}
|
||||
+10
@@ -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
|
||||
}
|
||||
+52
@@ -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 ""
|
||||
}
|
||||
+10
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user