[NI] Properly support UnsafeVariance annotation
#KT-38134 Fixed #KT-34433 Fixed #KT-31823 Fixed
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
class A<out K> {
|
||||
fun foo(x: @UnsafeVariance K): K = x
|
||||
}
|
||||
|
||||
fun test(a: A<*>): Any? {
|
||||
return a.foo("OK")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return test(A<String>()) as String
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// FIR_IDENTICAL
|
||||
|
||||
class Foo<out T>(val baz: Baz<T>)
|
||||
|
||||
class Bar {
|
||||
val foo: Foo<*> = TODO()
|
||||
|
||||
fun <T> bar(): Baz<T> {
|
||||
return foo.baz
|
||||
}
|
||||
}
|
||||
|
||||
typealias Baz<T> = (@UnsafeVariance T) -> Unit
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package
|
||||
|
||||
public final class Bar {
|
||||
public constructor Bar()
|
||||
public final val foo: Foo<*>
|
||||
public final fun </*0*/ T> bar(): Baz<T> /* = (@kotlin.UnsafeVariance T) -> kotlin.Unit */
|
||||
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 Foo</*0*/ out T> {
|
||||
public constructor Foo</*0*/ out T>(/*0*/ baz: Baz<T> /* = (@kotlin.UnsafeVariance T) -> kotlin.Unit */)
|
||||
public final val baz: Baz<T> /* = (@kotlin.UnsafeVariance T) -> kotlin.Unit */
|
||||
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 typealias Baz</*0*/ T> = (@kotlin.UnsafeVariance T) -> kotlin.Unit
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -REDUNDANT_PROJECTION
|
||||
|
||||
class FunctionHolder<out T : Any>(val f: (@UnsafeVariance T) -> Unit) {
|
||||
fun f2(v: @UnsafeVariance T) {}
|
||||
}
|
||||
|
||||
fun caller(
|
||||
holder1: FunctionHolder<out Any>,
|
||||
holder2: FunctionHolder<*>,
|
||||
holder3: FunctionHolder<Any>,
|
||||
a: Any
|
||||
) {
|
||||
holder1.f(a)
|
||||
holder1.f2(a)
|
||||
|
||||
holder2.f(a)
|
||||
holder2.f2(a)
|
||||
|
||||
holder3.f(a)
|
||||
holder3.f2(a)
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package
|
||||
|
||||
public fun caller(/*0*/ holder1: FunctionHolder<out kotlin.Any>, /*1*/ holder2: FunctionHolder<*>, /*2*/ holder3: FunctionHolder<kotlin.Any>, /*3*/ a: kotlin.Any): kotlin.Unit
|
||||
|
||||
public final class FunctionHolder</*0*/ out T : kotlin.Any> {
|
||||
public constructor FunctionHolder</*0*/ out T : kotlin.Any>(/*0*/ f: (@kotlin.UnsafeVariance T) -> kotlin.Unit)
|
||||
public final val f: (@kotlin.UnsafeVariance T) -> kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun f2(/*0*/ v: @kotlin.UnsafeVariance T): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
|
||||
interface A<out K> {
|
||||
fun foo(x: @UnsafeVariance K): Unit
|
||||
}
|
||||
|
||||
fun test(a: A<*>) {
|
||||
a.foo(null)
|
||||
a.foo(Any())
|
||||
}
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// FIR_IDENTICAL
|
||||
|
||||
interface A<out K> {
|
||||
fun foo(x: @UnsafeVariance K): Unit
|
||||
}
|
||||
|
||||
fun test(a: A<*>) {
|
||||
a.foo(<!NI;NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
a.foo(<!NI;TYPE_MISMATCH!>Any()<!>)
|
||||
a.foo(null)
|
||||
a.foo(Any())
|
||||
}
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
interface UpdatableRendering<out T : UpdatableRendering<T>> {
|
||||
fun canUpdateFrom(another: @UnsafeVariance T): Boolean
|
||||
}
|
||||
|
||||
internal fun Any.matchesRendering(other: Any): Boolean {
|
||||
return when {
|
||||
this::class != other::class -> false
|
||||
this !is UpdatableRendering<*> -> true
|
||||
else -> this.<!INAPPLICABLE_CANDIDATE!>canUpdateFrom<!>(other as UpdatableRendering<*>)
|
||||
}
|
||||
}
|
||||
compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceWithRecursiveGenerics.kt
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
interface UpdatableRendering<out T : UpdatableRendering<T>> {
|
||||
fun canUpdateFrom(another: @UnsafeVariance T): Boolean
|
||||
}
|
||||
|
||||
internal fun Any.matchesRendering(other: Any): Boolean {
|
||||
return when {
|
||||
this::class != other::class -> false
|
||||
this !is UpdatableRendering<*> -> true
|
||||
else -> <!DEBUG_INFO_SMARTCAST!>this<!>.canUpdateFrom(other as UpdatableRendering<*>)
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package
|
||||
|
||||
internal fun kotlin.Any.matchesRendering(/*0*/ other: kotlin.Any): kotlin.Boolean
|
||||
|
||||
public interface UpdatableRendering</*0*/ out T : UpdatableRendering<T>> {
|
||||
public abstract fun canUpdateFrom(/*0*/ another: @kotlin.UnsafeVariance T): kotlin.Boolean
|
||||
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