Call completer: safe call with nullable receiver has nullable return type #KT-11007 Fixed

This commit is contained in:
Mikhail Glukhikh
2016-02-12 12:42:29 +03:00
committed by Mikhail Glukhikh
parent 4cd7193047
commit 17593e4ef6
6 changed files with 85 additions and 4 deletions
+2 -3
View File
@@ -53,9 +53,8 @@ L3 [after local declaration]:
r({ throw Exception() }) -> <v1> PREV:[jmp?(L3)]
mark(let { throw Exception() })
call(let { throw Exception() }, let|<v0>, <v1>)
jmp(error) NEXT:[<ERROR>]
L2 [result of call]:
mark(fn()?.let { throw Exception() } ?: "unreachable?") PREV:[jf(L2)]
mark(fn()?.let { throw Exception() } ?: "unreachable?") PREV:[jf(L2), call(let { throw Exception() }, let|<v0>, <v1>)]
jt(L6|!<v2>) NEXT:[mark("unreachable?"), merge(fn()?.let { throw Exception() } ?: "unreachable?"|!<v2>, <v3>) -> <v4>]
mark("unreachable?")
r("unreachable?") -> <v3>
@@ -67,7 +66,7 @@ L6 [after elvis operator]:
L1:
1 <END> NEXT:[<SINK>]
error:
<ERROR> PREV:[jmp(error)]
<ERROR> PREV:[]
sink:
<SINK> PREV:[<ERROR>, <END>, d({ throw Exception() })]
=====================
@@ -0,0 +1,43 @@
// See KT-11007: Wrong smart cast to not-null type after safe calls in if / when expression
val String.copy: String
get() = this
fun foo() {
val s: String? = null
val ss = if (true) {
s?.length
} else {
s?.length
}
ss<!UNSAFE_CALL!>.<!>hashCode() // Smart-cast to Int, should be unsafe call
val sss = if (true) {
s?.copy
}
else {
s?.copy
}
sss<!UNSAFE_CALL!>.<!>length
}
class My {
val String.copy2: String
get() = this
fun foo() {
val s: String? = null
val ss = if (true) {
s?.length
} else {
s?.length
}
ss<!UNSAFE_CALL!>.<!>hashCode()
val sss = if (true) {
s?.copy2
}
else {
s?.copy2
}
sss<!UNSAFE_CALL!>.<!>length
}
}
@@ -0,0 +1,13 @@
package
public val kotlin.String.copy: kotlin.String
public fun foo(): kotlin.Unit
public final class My {
public constructor My()
public final val kotlin.String.copy2: kotlin.String
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}