Elvis / if / when now infer error type in case of ErrorType + Nothing #KT-6665 Fixed

(cherry picked from commit 9a50a0b)
This commit is contained in:
Mikhail Glukhikh
2016-06-16 17:45:17 +03:00
committed by Mikhail Glukhikh
parent 49fb9ff424
commit 5ccbf47531
8 changed files with 92 additions and 14 deletions
@@ -9,7 +9,7 @@ else {
{ true } <!USELESS_ELVIS_ON_LAMBDA_EXPRESSION!>?:<!> null!!
}
val <!IMPLICIT_NOTHING_PROPERTY_TYPE!>ww<!> = if (true) {
val ww = if (true) {
<!TYPE_MISMATCH!>{ true }<!> <!USELESS_ELVIS_ON_LAMBDA_EXPRESSION!>?:<!> null!!
}
else if (true) {
@@ -7,6 +7,6 @@ public val bbbb: (() -> kotlin.Boolean)?
public val n: kotlin.Nothing
public val v: () -> kotlin.Boolean
public val w: () -> kotlin.Boolean
public val ww: kotlin.Nothing
public val ww: ???
public fun f(/*0*/ x: kotlin.Long?): kotlin.Long
public fun l(): (() -> kotlin.Boolean)?
@@ -0,0 +1,48 @@
// See KT-6665: unresolved reference (v.bar) should not produce "unreachable code" after it
fun foo(): Int {
val v = 1
val <!UNUSED_VARIABLE!>c<!> = v.<!UNRESOLVED_REFERENCE!>bar<!> ?: return 0
return 42
}
fun foo2(): Int {
val v = 1
val c = if (true) v.<!UNRESOLVED_REFERENCE!>bar<!> else return 3
val <!UNUSED_VARIABLE!>b<!> = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>c<!>
return 42
}
fun foo3(): Int {
val v = 1
val c = when {
true -> v.<!UNRESOLVED_REFERENCE!>bar<!>
else -> return 3
}
val <!UNUSED_VARIABLE!>b<!> = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>c<!>
return 42
}
// Type + ErrorType should give Type, unless Type is Nothing
fun bar(): Int {
val v = 1
val c = v.<!UNRESOLVED_REFERENCE!>bar<!> ?: 42
return c
}
fun bar2(): Int {
val v = 1
val c = if (true) v.<!UNRESOLVED_REFERENCE!>bar<!> else 3
val b = c
return b
}
fun bar3(): Int {
val v = 1
val c = when {
true -> v.<!UNRESOLVED_REFERENCE!>bar<!>
else -> 3
}
val b = c
return b
}
@@ -0,0 +1,8 @@
package
public fun bar(): kotlin.Int
public fun bar2(): kotlin.Int
public fun bar3(): kotlin.Int
public fun foo(): kotlin.Int
public fun foo2(): kotlin.Int
public fun foo3(): kotlin.Int