[NI] Preserve nullability of resulting type from CST if it's possible

Consider common supertype of `S` and `Nothing`, where `S` has nullable
 upper bound or it's flexible. Before the fix, result was `S?`, which
 is correct but too conservative. Now, we'll preserve nullability of
 resulting type if it's already nullable.

 This happened because we were failing to find path of not-nullable
 types from `Nothing` to `S`, which should obviously exists by
 semantics of Nothing
This commit is contained in:
Mikhail Zarechenskiy
2019-03-04 01:18:07 +03:00
parent 9b3e17f0d7
commit 93e79afab4
5 changed files with 59 additions and 1 deletions
@@ -0,0 +1,20 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface Base<out T>
class ParameterizedChild<out R> : Base<R>
class Child : Base<Nothing>
fun <K> elvis(x: K?, y: K): K = TODO()
fun <K> select(x: K, y: K): K = TODO()
fun <V> myRun(f: () -> V): V = f()
fun <S> test1(a: ParameterizedChild<S>?, b: Child): Base<S> = myRun {
elvis(a, b)
}
fun <S> test2(a: S?, b: S): S = <!TYPE_MISMATCH!>myRun {
<!TYPE_MISMATCH!>select(a, b)<!>
}<!>
@@ -0,0 +1,27 @@
package
public fun </*0*/ K> elvis(/*0*/ x: K?, /*1*/ y: K): K
public fun </*0*/ V> myRun(/*0*/ f: () -> V): V
public fun </*0*/ K> select(/*0*/ x: K, /*1*/ y: K): K
public fun </*0*/ S> test1(/*0*/ a: ParameterizedChild<S>?, /*1*/ b: Child): Base<S>
public fun </*0*/ S> test2(/*0*/ a: S?, /*1*/ b: S): S
public interface Base</*0*/ out T> {
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
}
public final class Child : Base<kotlin.Nothing> {
public constructor Child()
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
}
public final class ParameterizedChild</*0*/ out R> : Base<R> {
public constructor ParameterizedChild</*0*/ out R>()
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
}