[NI] Fix CST calculation for covariant type projections

This commit is contained in:
Mikhail Zarechenskiy
2020-01-16 13:34:34 +03:00
parent 082cbae74a
commit 4f74515508
6 changed files with 48 additions and 2 deletions
@@ -388,7 +388,8 @@ object NewCommonSuperTypeCalculator {
return if (equalToEachOtherType == null) {
createTypeArgument(commonSuperType(argumentTypes, depth + 1), TypeVariance.OUT)
} else {
createTypeArgument(equalToEachOtherType.getType(), TypeVariance.INV)
val thereIsNotInv = arguments.any { it.getVariance() != TypeVariance.INV }
createTypeArgument(equalToEachOtherType.getType(), if (thereIsNotInv) TypeVariance.OUT else TypeVariance.INV)
}
} else {
val type = intersectTypes(arguments.map { it.getType() })
@@ -16,5 +16,5 @@ fun <R> foo(f: () -> R): R = f()
fun test(n: Number) {
val a = select(foo { JavaTest.createNumberArray() }, emptyArray())
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.Array<(kotlin.Number..kotlin.Number?)>..kotlin.Array<(kotlin.Number..kotlin.Number?)>?)")!>a<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.Array<(kotlin.Number..kotlin.Number?)>..kotlin.Array<out (kotlin.Number..kotlin.Number?)>?)")!>a<!>
}
@@ -0,0 +1,20 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// FILE: Foo.java
public class Foo {
public static <K, V> void create(java.util.Map<? extends K, ? extends V> m) { return null; }
}
// FILE: test.kt
fun test(properties: Map<String, String>, nullableProperties: Map<String, String>?) {
val f1 = Foo.create(select1(properties, myEmptyMap()))
val f2 = Foo.create(nullableProperties ?: myEmptyMap())
}
fun <T, R> myEmptyMap(): Map<T, R> = TODO()
@Suppress("INVISIBLE_REFERENCE")
fun <S> select1(x: S, y: S): @kotlin.internal.Exact S = y
@@ -0,0 +1,15 @@
package
public fun </*0*/ T, /*1*/ R> myEmptyMap(): kotlin.collections.Map<T, R>
@kotlin.Suppress(names = {"INVISIBLE_REFERENCE"}) public fun </*0*/ S> select1(/*0*/ x: S, /*1*/ y: S): S
public fun test(/*0*/ properties: kotlin.collections.Map<kotlin.String, kotlin.String>, /*1*/ nullableProperties: kotlin.collections.Map<kotlin.String, kotlin.String>?): kotlin.Unit
public open class Foo {
public constructor Foo()
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
// Static members
public open fun </*0*/ K : kotlin.Any!, /*1*/ V : kotlin.Any!> create(/*0*/ m: (kotlin.collections.MutableMap<out K!, out V!>..kotlin.collections.Map<out K!, V!>?)): kotlin.Unit
}
@@ -1902,6 +1902,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/correctMember.kt");
}
@TestMetadata("elvisOperatorAgainstFlexibleType.kt")
public void testElvisOperatorAgainstFlexibleType() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/elvisOperatorAgainstFlexibleType.kt");
}
@TestMetadata("extensionPriority.kt")
public void testExtensionPriority() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionPriority.kt");
@@ -1902,6 +1902,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/correctMember.kt");
}
@TestMetadata("elvisOperatorAgainstFlexibleType.kt")
public void testElvisOperatorAgainstFlexibleType() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/elvisOperatorAgainstFlexibleType.kt");
}
@TestMetadata("extensionPriority.kt")
public void testExtensionPriority() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionPriority.kt");