[NI] Properly support UnsafeVariance annotation

#KT-38134 Fixed
 #KT-34433 Fixed
 #KT-31823 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-04-16 04:27:22 +03:00
parent 1614c1b8a6
commit 4ffcbc0c2f
20 changed files with 244 additions and 20 deletions
@@ -9154,11 +9154,26 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/typeParameterBounds.kt");
}
@TestMetadata("unsafeVarianceInAliasedFunctionalType.kt")
public void testUnsafeVarianceInAliasedFunctionalType() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceInAliasedFunctionalType.kt");
}
@TestMetadata("unsafeVarianceOnInputTypeOfFunctionalType.kt")
public void testUnsafeVarianceOnInputTypeOfFunctionalType() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceOnInputTypeOfFunctionalType.kt");
}
@TestMetadata("unsafeVarianceStar.kt")
public void testUnsafeVarianceStar() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceStar.kt");
}
@TestMetadata("unsafeVarianceWithRecursiveGenerics.kt")
public void testUnsafeVarianceWithRecursiveGenerics() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceWithRecursiveGenerics.kt");
}
@TestMetadata("varargs.kt")
public void testVarargs() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/varargs.kt");
@@ -12105,6 +12105,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
public void testLastExpressionOfLambdaWithNothingConstraint() throws Exception {
runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt");
}
@TestMetadata("unsafeVarianceCodegen.kt")
public void testUnsafeVarianceCodegen() throws Exception {
runTest("compiler/testData/codegen/box/inference/unsafeVarianceCodegen.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses")
@@ -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
}
@@ -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
@@ -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
@@ -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)
}
@@ -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
}
@@ -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())
}
@@ -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())
}
@@ -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<*>)
}
}
@@ -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<*>)
}
}
@@ -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
}
@@ -9161,11 +9161,26 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/typeParameterBounds.kt");
}
@TestMetadata("unsafeVarianceInAliasedFunctionalType.kt")
public void testUnsafeVarianceInAliasedFunctionalType() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceInAliasedFunctionalType.kt");
}
@TestMetadata("unsafeVarianceOnInputTypeOfFunctionalType.kt")
public void testUnsafeVarianceOnInputTypeOfFunctionalType() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceOnInputTypeOfFunctionalType.kt");
}
@TestMetadata("unsafeVarianceStar.kt")
public void testUnsafeVarianceStar() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceStar.kt");
}
@TestMetadata("unsafeVarianceWithRecursiveGenerics.kt")
public void testUnsafeVarianceWithRecursiveGenerics() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceWithRecursiveGenerics.kt");
}
@TestMetadata("varargs.kt")
public void testVarargs() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/varargs.kt");
@@ -9156,11 +9156,26 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/typeParameterBounds.kt");
}
@TestMetadata("unsafeVarianceInAliasedFunctionalType.kt")
public void testUnsafeVarianceInAliasedFunctionalType() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceInAliasedFunctionalType.kt");
}
@TestMetadata("unsafeVarianceOnInputTypeOfFunctionalType.kt")
public void testUnsafeVarianceOnInputTypeOfFunctionalType() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceOnInputTypeOfFunctionalType.kt");
}
@TestMetadata("unsafeVarianceStar.kt")
public void testUnsafeVarianceStar() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceStar.kt");
}
@TestMetadata("unsafeVarianceWithRecursiveGenerics.kt")
public void testUnsafeVarianceWithRecursiveGenerics() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/unsafeVarianceWithRecursiveGenerics.kt");
}
@TestMetadata("varargs.kt")
public void testVarargs() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/projectionsScope/varargs.kt");
@@ -13320,6 +13320,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
public void testLastExpressionOfLambdaWithNothingConstraint() throws Exception {
runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt");
}
@TestMetadata("unsafeVarianceCodegen.kt")
public void testUnsafeVarianceCodegen() throws Exception {
runTest("compiler/testData/codegen/box/inference/unsafeVarianceCodegen.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses")
@@ -13320,6 +13320,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
public void testLastExpressionOfLambdaWithNothingConstraint() throws Exception {
runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt");
}
@TestMetadata("unsafeVarianceCodegen.kt")
public void testUnsafeVarianceCodegen() throws Exception {
runTest("compiler/testData/codegen/box/inference/unsafeVarianceCodegen.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses")
@@ -12105,6 +12105,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
public void testLastExpressionOfLambdaWithNothingConstraint() throws Exception {
runTest("compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt");
}
@TestMetadata("unsafeVarianceCodegen.kt")
public void testUnsafeVarianceCodegen() throws Exception {
runTest("compiler/testData/codegen/box/inference/unsafeVarianceCodegen.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses")