[NI] Discriminate Nothing? result type from nullability constraints
Nullability constraints should not be chosen when proper argument constraints for variables in contravariant position present. ^KT-32106 Fixed ^KT-33166 Fixed
This commit is contained in:
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
open class Cls
|
||||
|
||||
abstract class In<in I>
|
||||
class SubIn : In<Cls?>()
|
||||
|
||||
inline fun <reified T : Cls> materialize(): T? = TODO()
|
||||
|
||||
fun <D> transform(transformer: In<D>, data: D): Unit = TODO()
|
||||
|
||||
fun test(subIn: SubIn) {
|
||||
transform(subIn, materialize()) // D should be inferred to Cls?, not Nothing?
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
open class Cls
|
||||
|
||||
abstract class In<in I>
|
||||
class SubIn : In<Cls?>()
|
||||
|
||||
inline fun <reified T : Cls> materialize(): T? = TODO()
|
||||
|
||||
fun <D> transform(transformer: In<D>, data: D): Unit = TODO()
|
||||
|
||||
fun test(subIn: SubIn) {
|
||||
transform(subIn, materialize()) // D should be inferred to Cls?, not Nothing?
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package
|
||||
|
||||
public inline fun </*0*/ reified T : Cls> materialize(): T?
|
||||
public fun test(/*0*/ subIn: SubIn): kotlin.Unit
|
||||
public fun </*0*/ D> transform(/*0*/ transformer: In<D>, /*1*/ data: D): kotlin.Unit
|
||||
|
||||
public open class Cls {
|
||||
public constructor Cls()
|
||||
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 abstract class In</*0*/ in I> {
|
||||
public constructor In</*0*/ in I>()
|
||||
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 SubIn : In<Cls?> {
|
||||
public constructor SubIn()
|
||||
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
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun <K> id(arg: K): K = arg
|
||||
|
||||
val v = id(null)
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun <K> id(arg: K): K = arg
|
||||
|
||||
val v = <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing?")!>id(null)<!>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public val v: kotlin.Nothing?
|
||||
public fun </*0*/ K> id(/*0*/ arg: K): K
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
|
||||
|
||||
class Out<out T : Any>(result: T?)
|
||||
|
||||
fun main() {
|
||||
val a = Out(null)
|
||||
|
||||
a
|
||||
|
||||
var b: Out<Int>? = null
|
||||
b = a
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
class Query<out T : Any> private constructor(
|
||||
private val result: T?,
|
||||
private val error: Throwable?,
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
class Query<out T : Any> private constructor(
|
||||
private val result: T?,
|
||||
private val error: Throwable?,
|
||||
|
||||
+1
-1
@@ -36,7 +36,6 @@ fun testOK(first: First, bound: Bound, second: Second) {
|
||||
strictSelect(OutB(first), OutB(bound))
|
||||
strictSelect(In(first), In(bound))
|
||||
strictSelect(InB(first), InB(bound))
|
||||
strictSelect(InB(first), InB(second)) // different behaviour in contravariant position
|
||||
|
||||
val out: Out<Bound> = strictSelect(Out(first), Out(second))
|
||||
val outb: OutB<Bound> = strictSelect(OutB(first), OutB(second))
|
||||
@@ -49,6 +48,7 @@ fun testFail(first: First, bound: Bound, second: Second) {
|
||||
strictSelect(Inv(first), Inv(bound))
|
||||
strictSelect(Out(first), Out(second))
|
||||
strictSelect(In(first), In(second))
|
||||
strictSelect(InB(first), InB(second))
|
||||
strictSelect(Out(Inv(first)), Out(Inv(second)))
|
||||
strictSelect(In(Inv(first)), In(Inv(second)))
|
||||
}
|
||||
|
||||
+1
-1
@@ -36,7 +36,6 @@ fun testOK(first: First, bound: Bound, second: Second) {
|
||||
strictSelect(OutB(first), OutB(bound))
|
||||
strictSelect(In(first), In(bound))
|
||||
strictSelect(InB(first), InB(bound))
|
||||
<!OI;TYPE_INFERENCE_ONLY_INPUT_TYPES!>strictSelect<!>(InB(first), InB(second)) // different behaviour in contravariant position
|
||||
|
||||
val out: Out<Bound> = strictSelect(Out(first), Out(second))
|
||||
val outb: OutB<Bound> = strictSelect(OutB(first), OutB(second))
|
||||
@@ -49,6 +48,7 @@ fun testFail(first: First, bound: Bound, second: Second) {
|
||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES!>strictSelect<!>(Inv(first), Inv(bound))
|
||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES!>strictSelect<!>(Out(first), Out(second))
|
||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES!>strictSelect<!>(In(first), In(second))
|
||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES!>strictSelect<!>(InB(first), InB(second))
|
||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES!>strictSelect<!>(Out(Inv(first)), Out(Inv(second)))
|
||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES!>strictSelect<!>(In(Inv(first)), In(Inv(second)))
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ fun test1(): Map<Int, Int> = run {
|
||||
}
|
||||
|
||||
fun test2(): Map<Int, Int> = run {
|
||||
<!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, NI;TYPE_MISMATCH!>try {
|
||||
<!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, NI;TYPE_MISMATCH!>try {
|
||||
emptyMap()
|
||||
} catch (e: ExcA) {
|
||||
<!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH, OI;TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>mapOf(<!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH!>"" to ""<!>)<!>
|
||||
|
||||
@@ -2,10 +2,10 @@ FILE fqName:<root> fileName:/whenReturn.kt
|
||||
FUN name:toString visibility:public modality:FINAL <> (grade:kotlin.String) returnType:kotlin.String
|
||||
VALUE_PARAMETER name:grade index:0 type:kotlin.String
|
||||
BLOCK_BODY
|
||||
BLOCK type=kotlin.String origin=WHEN
|
||||
BLOCK type=kotlin.Nothing origin=WHEN
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.String [val]
|
||||
GET_VAR 'grade: kotlin.String declared in <root>.toString' type=kotlin.String origin=null
|
||||
WHEN type=kotlin.String origin=WHEN
|
||||
WHEN type=kotlin.Nothing origin=WHEN
|
||||
BRANCH
|
||||
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
|
||||
arg0: GET_VAR 'val tmp_0: kotlin.String [val] declared in <root>.toString' type=kotlin.String origin=null
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
FILE fqName:<root> fileName:/nonLocalReturn.kt
|
||||
FUN name:test0 visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||
BLOCK_BODY
|
||||
CALL 'public final fun run <R> (block: kotlin.Function0<R of kotlin.run>): R of kotlin.run [inline] declared in kotlin' type=kotlin.Unit origin=null
|
||||
<R>: kotlin.Unit
|
||||
block: FUN_EXPR type=kotlin.Function0<kotlin.Unit> origin=LAMBDA
|
||||
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Unit
|
||||
CALL 'public final fun run <R> (block: kotlin.Function0<R of kotlin.run>): R of kotlin.run [inline] declared in kotlin' type=kotlin.Nothing origin=null
|
||||
<R>: kotlin.Nothing
|
||||
block: FUN_EXPR type=kotlin.Function0<kotlin.Nothing> origin=LAMBDA
|
||||
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Nothing
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test0 (): kotlin.Unit declared in <root>'
|
||||
GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
|
||||
@@ -33,12 +33,12 @@ FILE fqName:<root> fileName:/nonLocalReturn.kt
|
||||
block: FUN_EXPR type=kotlin.Function0<kotlin.Unit> origin=LAMBDA
|
||||
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Unit
|
||||
BLOCK_BODY
|
||||
CALL 'public final fun run <R> (block: kotlin.Function0<R of kotlin.run>): R of kotlin.run [inline] declared in kotlin' type=kotlin.Unit origin=null
|
||||
<R>: kotlin.Unit
|
||||
block: FUN_EXPR type=kotlin.Function0<kotlin.Unit> origin=LAMBDA
|
||||
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Unit
|
||||
CALL 'public final fun run <R> (block: kotlin.Function0<R of kotlin.run>): R of kotlin.run [inline] declared in kotlin' type=kotlin.Nothing origin=null
|
||||
<R>: kotlin.Nothing
|
||||
block: FUN_EXPR type=kotlin.Function0<kotlin.Nothing> origin=LAMBDA
|
||||
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Nothing
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='local final fun <anonymous> (): kotlin.Unit declared in <root>.test3.<anonymous>'
|
||||
RETURN type=kotlin.Nothing from='local final fun <anonymous> (): kotlin.Nothing declared in <root>.test3.<anonymous>'
|
||||
GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
|
||||
FUN name:testLrmFoo1 visibility:public modality:FINAL <> (ints:kotlin.collections.List<kotlin.Int>) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:ints index:0 type:kotlin.collections.List<kotlin.Int>
|
||||
|
||||
Reference in New Issue
Block a user