[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:
+20
@@ -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)<!>
|
||||
}<!>
|
||||
+27
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user