[NI] Remove Nothing result type restriction in most cases
Make Nothing as result type not suitable only for if, when, try and ?: special functions.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// See KT-10913 Bogus unreachable code warning
|
||||
|
||||
fun fn() : String? = null
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// See KT-10913 Bogus unreachable code warning
|
||||
|
||||
fun fn() : String? = null
|
||||
@@ -8,6 +7,6 @@ fun foo(): String {
|
||||
}
|
||||
fun bar(): String {
|
||||
val x = fn() ?: return ""
|
||||
<!UNREACHABLE_CODE!>val <!UNUSED_VARIABLE!>y<!> =<!> x<!UNNECESSARY_SAFE_CALL!>?.<!>let { throw Exception() } <!NI;UNREACHABLE_CODE, NI;USELESS_ELVIS, OI;UNREACHABLE_CODE, OI;USELESS_ELVIS!>?: "unreachable"<!>
|
||||
<!UNREACHABLE_CODE!>val <!UNUSED_VARIABLE!>y<!> =<!> x<!UNNECESSARY_SAFE_CALL!>?.<!>let { throw Exception() } <!UNREACHABLE_CODE, USELESS_ELVIS!>?: "unreachable"<!>
|
||||
<!UNREACHABLE_CODE!>return y<!>
|
||||
}
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
fun <K> select2(x: K, y: K): K = TODO()
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
class Query<out T : Any> private constructor(
|
||||
private val result: T?,
|
||||
private val error: Throwable?,
|
||||
val inProgress: Boolean
|
||||
) {
|
||||
companion object {
|
||||
val inProgress = Query(null, null, true)
|
||||
fun forError(e: Throwable) = Query(null, e, false)
|
||||
fun <T : Any> forResult(result: T) = Query(result, null, false)
|
||||
}
|
||||
}
|
||||
|
||||
class MutableLiveData<T> {
|
||||
var value: Query<Int> = null!!
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val liveData = MutableLiveData<Query<Int>>()
|
||||
liveData.value = Query.inProgress // Type mismatch: inferred type is Query<Any> but Query<Int> was expected
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
class Query<out T : Any> private constructor(
|
||||
private val result: T?,
|
||||
private val error: Throwable?,
|
||||
val inProgress: Boolean
|
||||
) {
|
||||
companion object {
|
||||
val inProgress = Query(null, null, true)
|
||||
fun forError(e: Throwable) = Query(null, e, false)
|
||||
fun <T : Any> forResult(result: T) = Query(result, null, false)
|
||||
}
|
||||
}
|
||||
|
||||
class MutableLiveData<T> {
|
||||
var value: Query<Int> = null!!
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val liveData = MutableLiveData<Query<Int>>()
|
||||
liveData.value = Query.inProgress // Type mismatch: inferred type is Query<Any> but Query<Int> was expected
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package
|
||||
|
||||
public fun main(): kotlin.Unit
|
||||
|
||||
public final class MutableLiveData</*0*/ T> {
|
||||
public constructor MutableLiveData</*0*/ T>()
|
||||
public final var value: Query<kotlin.Int>
|
||||
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 Query</*0*/ out T : kotlin.Any> {
|
||||
private constructor Query</*0*/ out T : kotlin.Any>(/*0*/ result: T?, /*1*/ error: kotlin.Throwable?, /*2*/ inProgress: kotlin.Boolean)
|
||||
private final val error: kotlin.Throwable?
|
||||
public final val inProgress: kotlin.Boolean
|
||||
private final val result: 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 companion object Companion {
|
||||
private constructor Companion()
|
||||
public final val inProgress: Query<kotlin.Nothing>
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun forError(/*0*/ e: kotlin.Throwable): Query<kotlin.Nothing>
|
||||
public final fun </*0*/ T : kotlin.Any> forResult(/*0*/ result: T): Query<T>
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
val test: Int = <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH!>if (true) {
|
||||
val test: Int = <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, NI;TYPE_MISMATCH!>if (true) {
|
||||
when (2) {
|
||||
1 -> 1
|
||||
else -> <!OI;NULL_FOR_NONNULL_TYPE!>null<!>
|
||||
|
||||
@@ -7,19 +7,19 @@ val test1: (String) -> Boolean =
|
||||
|
||||
val test2: (String) -> Boolean =
|
||||
when {
|
||||
true -> <!NI;TYPE_MISMATCH!>{{ true }}<!>
|
||||
true -> {{ true }}
|
||||
else -> null!!
|
||||
}
|
||||
|
||||
val test3: (String) -> Boolean =
|
||||
when {
|
||||
true -> <!NI;TYPE_MISMATCH!>{ <!UNUSED_ANONYMOUS_PARAMETER!>s<!> -> true }<!>
|
||||
true -> { <!UNUSED_ANONYMOUS_PARAMETER!>s<!> -> true }
|
||||
else -> null!!
|
||||
}
|
||||
|
||||
val test4: (String) -> Boolean =
|
||||
when {
|
||||
true -> <!NI;TYPE_MISMATCH!>{ <!OI;EXPECTED_PARAMETERS_NUMBER_MISMATCH!><!UNUSED_ANONYMOUS_PARAMETER!>s1<!>, <!OI;CANNOT_INFER_PARAMETER_TYPE, UNUSED_ANONYMOUS_PARAMETER!>s2<!><!> -> true }<!>
|
||||
true -> <!NI;TYPE_MISMATCH!>{ <!EXPECTED_PARAMETERS_NUMBER_MISMATCH!><!UNUSED_ANONYMOUS_PARAMETER!>s1<!>, <!CANNOT_INFER_PARAMETER_TYPE, UNUSED_ANONYMOUS_PARAMETER!>s2<!><!> -> true }<!>
|
||||
else -> null!!
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ val <!OI;IMPLICIT_NOTHING_PROPERTY_TYPE!>test1<!> = when {
|
||||
}
|
||||
|
||||
val test1a: () -> Boolean = when {
|
||||
true -> <!NI;TYPE_MISMATCH!>{ { true } }<!>
|
||||
true -> { { true } }
|
||||
else -> TODO()
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ val <!OI;IMPLICIT_NOTHING_PROPERTY_TYPE!>test3<!> = when {
|
||||
}
|
||||
|
||||
val test3a: () -> Boolean = when {
|
||||
true -> <!NI;TYPE_MISMATCH!>{ { true } }<!>
|
||||
true -> <!NI;TYPE_MISMATCH!>{ { true } }<!>
|
||||
true -> { { true } }
|
||||
true -> { { true } }
|
||||
else -> TODO()
|
||||
}
|
||||
Reference in New Issue
Block a user