NI: don't filter flexible types during CST calculation and force return as result the first of such types

^KT-35658 Fixed
This commit is contained in:
Victor Petukhov
2019-12-19 19:48:38 +03:00
parent 51424ec598
commit 4309f53e11
10 changed files with 1198 additions and 17 deletions
@@ -11196,6 +11196,16 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/doNotInferFromBoundsOnly.kt");
}
@TestMetadata("flexibilityInCommonSuperTypeCalculation.kt")
public void testFlexibilityInCommonSuperTypeCalculation() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/flexibilityInCommonSuperTypeCalculation.kt");
}
@TestMetadata("flexibilityInCommonSuperTypeCalculation.ni.kt")
public void testFlexibilityInCommonSuperTypeCalculation_ni() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/flexibilityInCommonSuperTypeCalculation.ni.kt");
}
@TestMetadata("intersectUpperBounds.kt")
public void testIntersectUpperBounds() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/intersectUpperBounds.kt");
@@ -16,11 +16,9 @@
package org.jetbrains.kotlin.resolve.calls
import org.jetbrains.kotlin.types.AbstractNullabilityChecker
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.AbstractFlexibilityChecker.hasDifferentFlexibilityAtDepth
import org.jetbrains.kotlin.types.AbstractNullabilityChecker.hasPathByNotMarkedNullableNodes
import org.jetbrains.kotlin.types.AbstractTypeChecker
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
import org.jetbrains.kotlin.types.UnwrappedType
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext
import org.jetbrains.kotlin.types.model.*
@@ -32,10 +30,14 @@ object NewCommonSuperTypeCalculator {
fun TypeSystemCommonSuperTypesContext.commonSuperType(types: List<KotlinTypeMarker>): KotlinTypeMarker {
val maxDepth = types.maxBy { it.typeDepth() }?.typeDepth() ?: 0
return commonSuperType(types, -maxDepth)
return commonSuperType(types, -maxDepth, true)
}
private fun TypeSystemCommonSuperTypesContext.commonSuperType(types: List<KotlinTypeMarker>, depth: Int): KotlinTypeMarker {
private fun TypeSystemCommonSuperTypesContext.commonSuperType(
types: List<KotlinTypeMarker>,
depth: Int,
isTopLevelType: Boolean = false
): KotlinTypeMarker {
if (types.isEmpty()) throw IllegalStateException("Empty collection for input")
types.singleOrNull()?.let { return it }
@@ -69,6 +71,22 @@ object NewCommonSuperTypeCalculator {
val upperSuperType = commonSuperTypeForSimpleTypes(
types.map { it.upperBoundIfFlexible() }, depth, contextStubTypesEqualToAnything, contextStubTypesNotEqual
)
if (!isTopLevelType) {
val nonStubTypes =
types.filter { !isStubRelatedType(it.lowerBoundIfFlexible()) && !isStubRelatedType(it.upperBoundIfFlexible()) }
val equalToEachOtherTypes = nonStubTypes.filter { potentialCommonSuperType ->
nonStubTypes.all {
AbstractTypeChecker.equalTypes(this, it, potentialCommonSuperType)
}
}
if (equalToEachOtherTypes.isNotEmpty()) {
// TODO: merge flexibilities of type arguments instead of select the first suitable type
return equalToEachOtherTypes.first()
}
}
return createFlexibleType(lowerSuperType, upperSuperType)
}
@@ -109,8 +127,10 @@ object NewCommonSuperTypeCalculator {
val uniqueTypes = arrayListOf<SimpleTypeMarker>()
for (type in types) {
val isNewUniqueType = uniqueTypes.all {
!AbstractTypeChecker.equalTypes(contextStubTypesNotEqual, it, type) ||
it.typeConstructor().isIntegerLiteralTypeConstructor()
val equalsModuloFlexibility = AbstractTypeChecker.equalTypes(contextStubTypesNotEqual, it, type) &&
!it.typeConstructor().isIntegerLiteralTypeConstructor()
!equalsModuloFlexibility || hasDifferentFlexibilityAtDepth(listOf(it, type))
}
if (isNewUniqueType) {
uniqueTypes += type
@@ -121,7 +141,7 @@ object NewCommonSuperTypeCalculator {
// This function leaves only supertypes, i.e. A0 is a strong supertype for A iff A != A0 && A <: A0
// Explanation: consider types (A : A0, B : B0, A0, B0), then CST(A, B, A0, B0) == CST(CST(A, A0), CST(B, B0)) == CST(A0, B0)
private fun filterSupertypes(
private fun TypeSystemCommonSuperTypesContext.filterSupertypes(
list: List<SimpleTypeMarker>,
contextStubTypesNotEqual: AbstractTypeCheckerContext
): List<SimpleTypeMarker> {
@@ -130,7 +150,9 @@ object NewCommonSuperTypeCalculator {
while (iterator.hasNext()) {
val potentialSubtype = iterator.next()
val isSubtype = supertypes.any { supertype ->
supertype !== potentialSubtype && AbstractTypeChecker.isSubtypeOf(contextStubTypesNotEqual, potentialSubtype, supertype)
supertype !== potentialSubtype &&
AbstractTypeChecker.isSubtypeOf(contextStubTypesNotEqual, potentialSubtype, supertype) &&
!hasDifferentFlexibilityAtDepth(listOf(potentialSubtype, supertype))
}
if (isSubtype) iterator.remove()
@@ -352,14 +374,26 @@ object NewCommonSuperTypeCalculator {
// CS(Out<X>, Out<Y>) = Out<CS(X, Y)>
// CS(In<X>, In<Y>) = In<X & Y>
if (asOut) {
val type = commonSuperType(arguments.map { it.getType() }, depth + 1)
return if (parameter.getVariance() != TypeVariance.INV) return type.asTypeArgument() else createTypeArgument(
type,
TypeVariance.OUT
)
val argumentTypes = arguments.map { it.getType() }
val parameterIsNotInv = parameter.getVariance() != TypeVariance.INV
if (parameterIsNotInv) {
return commonSuperType(argumentTypes, depth + 1).asTypeArgument()
}
val equalToEachOtherType = arguments.firstOrNull { potentialSuperType ->
arguments.all { AbstractTypeChecker.equalTypes(this, it.getType(), potentialSuperType.getType()) }
}
return if (equalToEachOtherType == null) {
createTypeArgument(commonSuperType(argumentTypes, depth + 1), TypeVariance.OUT)
} else {
createTypeArgument(equalToEachOtherType.getType(), TypeVariance.INV)
}
} else {
val type = intersectTypes(arguments.map { it.getType() })
return if (parameter.getVariance() != TypeVariance.INV) return type.asTypeArgument() else createTypeArgument(
return if (parameter.getVariance() != TypeVariance.INV) type.asTypeArgument() else createTypeArgument(
type,
TypeVariance.IN
)
@@ -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<out (kotlin.Number..kotlin.Number?)>?)")!>a<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.Array<(kotlin.Number..kotlin.Number?)>..kotlin.Array<(kotlin.Number..kotlin.Number?)>?)")!>a<!>
}
@@ -0,0 +1,273 @@
// !DIAGNOSTICS: -UNSUPPORTED -UNUSED_EXPRESSION -DEBUG_INFO_SMARTCAST -USELESS_CAST -UNUSED_PARAMETER -UNCHECKED_CAST -CAST_NEVER_SUCCEEDS -UNUSED_VARIABLE -UNREACHABLE_CODE -DEBUG_INFO_CONSTANT
// !LANGUAGE: -NewInference
// SKIP_TXT
// FILE: Test.java
import java.util.List;
public class Test {
public static B foo() { return null; }
public static <T> T bar() { return null; }
public static <T> T id(T x) { return null; }
public static <T> List<T> getList(T x) { return null; }
public static List getRawList() { return null; }
}
// FILE: main.kt
class A<T>(x: T)
class B
fun <T> select(vararg x: T): T = null as T
fun case_1() {
val x = Test.foo() // B!
val result_1 = select(A(x), A(B()))
val result_2 = select(A(B()), A(x), A(if (true) B() else null))
val result_3 = select(A(x), A(if (true) B() else null))
result_1
result_2
result_3
}
fun case_2() {
val x = Test.bar<Any>() // Any!
val y: Any? = null
val result = select(A(Any()), A(y), A(x))
result
}
fun <T> case_3() {
val x = Test.bar<T>() // T!
val y: T? = null
val result = select(A(y), A(x), A(null as T))
result
}
fun case_4() {
val x = Test.bar<Nothing>() // Nothing!
val y = null // Nothing?
val result = select(A(x), A(y), A(return))
result
}
class C<T, K, L>(x: T, y: K, z: L)
fun case_5() {
val x = Test.foo() // B!
val y: B? = null
val result_1 = select(C(x, B(), 10), C(B(), x, 10))
val result_2 = select(C(B(), x, y), C(x, B(), y), C(y, x, B()), C(x, y, B()), C(y, B(), x), C(B(), y, x))
result_1
result_2
}
fun case_6() {
val x1 = Test.bar<C<C<A<Float>, B, Int>, B, B>>() // C<C<A<Float>, B, Int>, B, B>!
val x2 = C(null as C<A<Float?>, B?, Int>?, Test.id(B()), B()) // C<C<A<Float?>, B?, Int>?, B?, B>
val x3 = C(C(A(Test.id(1f)), B(), Test.id(1)), Test.id(B()), B()) // C<C<A<Float!>, B, Int!>, B!, B>
val x4 = C(C(A(Test.id(3f)), null as B?, null as Int?), null as B?, null as B?) // C<C<A<Float?>?, B?, Int?>, B?, B?>
val x5 = C(Test.id(C(A(1f), Test.id(B()), 1)), B(), Test.id(B())) // C<C<A<Float>, B!, Int>!, B, B!>
val x6 = Test.id(C(select(C(Test.id(A(1f)), null as B?, null as Int?), null), Test.id(B()), null as B?)) // C<C<A<Float!>, B?, Int?>?, B!, B?>!
val x7 = C(C(Test.id(A(1f)), B(), 1), B(), B()) // C<C<A<Float>!, B, Int>, B, B>
val x8 = C(Test.id(C(null as A<Float?>?, B(), null as Int?)), null as B?, Test.id(B())) // C<C<A<Float?>?, B, Int?>, B?, B>
val x9 = null as C<C<A<Float>, B?, Int>, B, B>? // C<C<A<Float>, B?, Int>, B, B>?
val result_1 = select(x1, x2, x3, x4, x5, x6, x7, x8, x9)
val result_2 = select(x9, x8, x7, x6, x5, x4, x3, x2, x1)
val result_3 = select(x5, x7, x9, x3, x1, x2, x8, x4, x6)
result_1
result_2
result_3
}
fun case_7() {
val x0: Int = 1
val x1 = C(A(Test.id(x0)), B(), B())
val x2 = C(Test.id(A(1)), B(), B())
x1
x2
val result_5 = select(x1, x2)
result_5
}
fun case_8() {
val x1 = A(10)
val x2 = select(A(""), null)
val x3 = Test.id(A(null))
val result_1 = select(x1, x2, x3)
result_1
}
fun case_9() {
val x1 = A(A(10))
val x2 = A(select(A(""), null))
val x3 = A(Test.id(A('s')))
val result_1 = select(x1, x2, x3)
result_1
}
fun case_10() {
val x1 = 10
val x2 = select(10, null)
val x3 = Test.id(10)
val result_1 = select(x2, x1, x3)
val result_2 = select(x2, x3, x1)
val result_3 = select(x1, x2, x3)
val result_4 = select(x1, x3, x2)
val result_5 = select(x3, x2, x1)
val result_6 = select(x3, x1, x2)
result_1
result_2
result_3
result_4
result_5
result_6
}
fun <T> case_11(y: T) {
val x1 = Test.bar<T>() // T!
val x2 = select(y, null)
if (y != null) {
val x3 = Test.id(y) // T!
val result_1 = select(A(y), A(x1))
val result_2 = select(A(y), A(x1), A(x2))
val result_3 = select(A(y), A(x3), A(x2))
val result_4 = select(A(y as T), A(x1))
val result_5 = select(A(y as T), A(x1), A(x2))
val result_6 = select(A(y as T), A(x3), A(x2))
val result_7 = select(A(y as T), A(x1))
val result_8 = select(A(y as T), A(x3))
val result_9 = select(A(x3), A(y as T))
val result_10 = select(y, x1)
val result_11 = select(y, x2, x2)
val result_12 = select(y, x3, x2)
val result_13 = select(y as T, x1)
val result_14 = select(y as T, x1, x2)
val result_15 = select(y as T, x3, x2)
val result_16 = select(y as T, x1)
val result_17 = select(y as T, x3)
val result_18 = select(x3, y as T)
x1
x2
x3
y
result_1
result_2
result_3
result_4
result_5
result_6
result_7
result_8
result_9
result_10
result_11
result_12
result_13
result_14
result_15
result_16
result_17
result_18
}
}
fun case_12() {
val x1 = Test.getList(10)
val x2 = null as MutableList<Int>
val x3 = select(null as List<Int>, null)
val result_1 = select(x1, x2)
val result_2 = select(x2, x1)
val result_3 = select(x2, x1, x3)
val result_4 = select(x3, x1)
val result_5 = select(A(x1), A(x2))
val result_6 = select(A(x2), A(x1))
val result_7 = select(A(x3), A(x1), A(x2))
val result_8 = select(A(x1), A(x3))
result_1
result_2
result_3
result_4
result_5
result_6
result_7
result_8
}
fun case_13() {
val x1 = Test.getList(10)
val x2: dynamic = null
val x3 = null as MutableList<Int>
val x4 = select(null as List<Int>, null)
val result_1 = <!INAPPLICABLE_CANDIDATE!>select<!>(x1, x2, x3, x4)
val result_2 = <!INAPPLICABLE_CANDIDATE!>select<!>(x2, x1)
val result_3 = <!INAPPLICABLE_CANDIDATE!>select<!>(x2, x1, x3)
val result_4 = <!INAPPLICABLE_CANDIDATE!>select<!>(x3, x2)
val result_5 = <!INAPPLICABLE_CANDIDATE!>select<!>(x4, x2)
val result_6 = <!INAPPLICABLE_CANDIDATE!>select<!>(x4, x3, x2)
val result_7 = <!INAPPLICABLE_CANDIDATE!>select<!>(A(x1), <!INAPPLICABLE_CANDIDATE!>A<!>(x2), A(x3), A(x4))
val result_8 = <!INAPPLICABLE_CANDIDATE!>select<!>(<!INAPPLICABLE_CANDIDATE!>A<!>(x2), A(x1))
val result_9 = <!INAPPLICABLE_CANDIDATE!>select<!>(<!INAPPLICABLE_CANDIDATE!>A<!>(x2), A(x1), A(x3))
val result_10 = <!INAPPLICABLE_CANDIDATE!>select<!>(A(x3), <!INAPPLICABLE_CANDIDATE!>A<!>(x2))
val result_11 = <!INAPPLICABLE_CANDIDATE!>select<!>(A(x4), <!INAPPLICABLE_CANDIDATE!>A<!>(x2))
val result_12 = <!INAPPLICABLE_CANDIDATE!>select<!>(A(x4), A(x3), <!INAPPLICABLE_CANDIDATE!>A<!>(x2))
result_1
result_2
result_3
result_4
result_5
result_6
result_7
result_8
result_9
result_10
result_11
result_12
}
fun case_14() {
val x1 = Test.getRawList()
val x2 = null as List<Int>
val x3 = select(null as MutableList<Int>, null)
val result_1 = select(x1, x2)
val result_2 = select(x2, x1)
val result_3 = select(x2, x1, x3)
val result_4 = select(x3, x1)
val result_5 = select(A(x1), A(x2))
val result_6 = select(A(x2), A(x1))
val result_7 = select(A(x3), A(x1), A(x2))
val result_8 = select(A(x1), A(x3))
result_1
result_2
result_3
result_4
result_5
result_6
result_7
result_8
}
@@ -0,0 +1,273 @@
// !DIAGNOSTICS: -UNSUPPORTED -UNUSED_EXPRESSION -DEBUG_INFO_SMARTCAST -USELESS_CAST -UNUSED_PARAMETER -UNCHECKED_CAST -CAST_NEVER_SUCCEEDS -UNUSED_VARIABLE -UNREACHABLE_CODE -DEBUG_INFO_CONSTANT
// !LANGUAGE: -NewInference
// SKIP_TXT
// FILE: Test.java
import java.util.List;
public class Test {
public static B foo() { return null; }
public static <T> T bar() { return null; }
public static <T> T id(T x) { return null; }
public static <T> List<T> getList(T x) { return null; }
public static List getRawList() { return null; }
}
// FILE: main.kt
class A<T>(x: T)
class B
fun <T> select(vararg x: T): T = null as T
fun case_1() {
val x = Test.foo() // B!
val result_1 = select(A(x), A(B()))
val result_2 = select(A(B()), A(x), A(if (true) B() else null))
val result_3 = select(A(x), A(if (true) B() else null))
<!DEBUG_INFO_EXPRESSION_TYPE("A<(B..B?)>")!>result_1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(B..B?)>")!>result_2<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(B..B?)>")!>result_3<!>
}
fun case_2() {
val x = Test.bar<Any>() // Any!
val y: Any? = null
val result = select(A(Any()), A(y), A(x))
<!DEBUG_INFO_EXPRESSION_TYPE("A<(kotlin.Any..kotlin.Any?)>")!>result<!>
}
fun <T> case_3() {
val x = Test.bar<T>() // T!
val y: T? = null
val result = select(A(y), A(x), A(null as T))
<!DEBUG_INFO_EXPRESSION_TYPE("A<(T..T?)>")!>result<!>
}
fun case_4() {
val x = Test.bar<Nothing>() // Nothing!
val y = null // Nothing?
val result = select(A(x), A(y), A(return))
<!DEBUG_INFO_EXPRESSION_TYPE("A<(kotlin.Nothing..kotlin.Nothing?)>")!>result<!>
}
class C<T, K, L>(x: T, y: K, z: L)
fun case_5() {
val x = Test.foo() // B!
val y: B? = null
val result_1 = select(C(x, B(), 10), C(B(), x, 10))
val result_2 = select(C(B(), x, y), C(x, B(), y), C(y, x, B()), C(x, y, B()), C(y, B(), x), C(B(), y, x))
<!DEBUG_INFO_EXPRESSION_TYPE("C<(B..B?), B, kotlin.Int>")!>result_1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("C<(B..B?), (B..B?), (B..B?)>")!>result_2<!>
}
fun case_6() {
val x1 = Test.bar<C<C<A<Float>, B, Int>, B, B>>() // C<C<A<Float>, B, Int>, B, B>!
val x2 = C(null as C<A<Float?>, B?, Int>?, Test.id(B()), B()) // C<C<A<Float?>, B?, Int>?, B?, B>
val x3 = C(C(A(Test.id(1f)), B(), Test.id(1)), Test.id(B()), B()) // C<C<A<Float!>, B, Int!>, B!, B>
val x4 = C(C(A(Test.id(3f)), null as B?, null as Int?), null as B?, null as B?) // C<C<A<Float?>?, B?, Int?>, B?, B?>
val x5 = C(Test.id(C(A(1f), Test.id(B()), 1)), B(), Test.id(B())) // C<C<A<Float>, B!, Int>!, B, B!>
val x6 = Test.id(C(select(C(Test.id(A(1f)), null as B?, null as Int?), null), Test.id(B()), null as B?)) // C<C<A<Float!>, B?, Int?>?, B!, B?>!
val x7 = C(C(Test.id(A(1f)), B(), 1), B(), B()) // C<C<A<Float>!, B, Int>, B, B>
val x8 = C(Test.id(C(null as A<Float?>?, B(), null as Int?)), null as B?, Test.id(B())) // C<C<A<Float?>?, B, Int?>, B?, B>
val x9 = null as C<C<A<Float>, B?, Int>, B, B>? // C<C<A<Float>, B?, Int>, B, B>?
val result_1 = select(x1, x2, x3, x4, x5, x6, x7, x8, x9)
val result_2 = select(x9, x8, x7, x6, x5, x4, x3, x2, x1)
val result_3 = select(x5, x7, x9, x3, x1, x2, x8, x4, x6)
<!DEBUG_INFO_EXPRESSION_TYPE("C<out C<out A<(kotlin.Float..kotlin.Float?)>?, (B..B?), (kotlin.Int..kotlin.Int?)>?, (B..B?), (B..B?)>?")!>result_1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("C<out C<out A<(kotlin.Float..kotlin.Float?)>?, (B..B?), (kotlin.Int..kotlin.Int?)>?, (B..B?), (B..B?)>?")!>result_2<!>
<!DEBUG_INFO_EXPRESSION_TYPE("C<out C<out A<(kotlin.Float..kotlin.Float?)>?, (B..B?), (kotlin.Int..kotlin.Int?)>?, (B..B?), (B..B?)>?")!>result_3<!>
}
fun case_7() {
val x0: Int = 1
val x1 = C(A(Test.id(x0)), B(), B())
val x2 = C(Test.id(A(1)), B(), B())
<!DEBUG_INFO_EXPRESSION_TYPE("C<A<(kotlin.Int..kotlin.Int?)>, B, B>")!>x1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("C<(A<kotlin.Int>..A<kotlin.Int>?), B, B>")!>x2<!>
val result_5 = select(x1, x2)
<!DEBUG_INFO_EXPRESSION_TYPE("C<A<(kotlin.Int..kotlin.Int?)>, B, B>")!>result_5<!>
}
fun case_8() {
val x1 = A(10)
val x2 = select(A(""), null)
val x3 = Test.id(A(null))
val result_1 = select(x1, x2, x3)
<!DEBUG_INFO_EXPRESSION_TYPE("A<out kotlin.Any?>?")!>result_1<!>
}
fun case_9() {
val x1 = A(A(10))
val x2 = A(select(A(""), null))
val x3 = A(Test.id(A('s')))
val result_1 = select(x1, x2, x3)
<!DEBUG_INFO_EXPRESSION_TYPE("A<out A<out kotlin.Any>?>")!>result_1<!>
}
fun case_10() {
val x1 = 10
val x2 = select(10, null)
val x3 = Test.id(10)
val result_1 = select(x2, x1, x3)
val result_2 = select(x2, x3, x1)
val result_3 = select(x1, x2, x3)
val result_4 = select(x1, x3, x2)
val result_5 = select(x3, x2, x1)
val result_6 = select(x3, x1, x2)
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int?")!>result_1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int?")!>result_2<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int?")!>result_3<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int?")!>result_4<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int?")!>result_5<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int?")!>result_6<!>
}
fun <T> case_11(y: T) {
val x1 = Test.bar<T>() // T!
val x2 = select(y, null)
if (y != null) {
val x3 = Test.id(y) // T!
val result_1 = select(A(y), A(x1))
val result_2 = select(A(y), A(x1), A(x2))
val result_3 = select(A(y), A(x3), A(x2))
val result_4 = select(A(y as T), A(x1))
val result_5 = select(A(y as T), A(x1), A(x2))
val result_6 = select(A(y as T), A(x3), A(x2))
val result_7 = select(A(y as T), A(x1))
val result_8 = select(A(y as T), A(x3))
val result_9 = select(A(x3), A(y as T))
val result_10 = select(y, x1)
val result_11 = select(y, x2, x2)
val result_12 = select(y, x3, x2)
val result_13 = select(y as T, x1)
val result_14 = select(y as T, x1, x2)
val result_15 = select(y as T, x3, x2)
val result_16 = select(y as T, x1)
val result_17 = select(y as T, x3)
val result_18 = select(x3, y as T)
<!DEBUG_INFO_EXPRESSION_TYPE("(T..T?)")!>x1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("T?")!>x2<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(T..T?)")!>x3<!>
<!DEBUG_INFO_EXPRESSION_TYPE("T")!>y<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<T>")!>result_1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(T..T?)>")!>result_2<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(T..T?)>")!>result_3<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<T>")!>result_4<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(T..T?)>")!>result_5<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(T..T?)>")!>result_6<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<T>")!>result_7<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<T>")!>result_8<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(T..T?)>")!>result_9<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(T..T?)")!>result_10<!>
<!DEBUG_INFO_EXPRESSION_TYPE("T?")!>result_11<!>
<!DEBUG_INFO_EXPRESSION_TYPE("T?")!>result_12<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(T..T?)")!>result_13<!>
<!DEBUG_INFO_EXPRESSION_TYPE("T?")!>result_14<!>
<!DEBUG_INFO_EXPRESSION_TYPE("T?")!>result_15<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(T..T?)")!>result_16<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(T..T?)")!>result_17<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(T..T?)")!>result_18<!>
}
}
fun case_12() {
val x1 = Test.getList(10)
val x2 = null as MutableList<Int>
val x3 = select(null as List<Int>, null)
val result_1 = select(x1, x2)
val result_2 = select(x2, x1)
val result_3 = select(x2, x1, x3)
val result_4 = select(x3, x1)
val result_5 = select(A(x1), A(x2))
val result_6 = select(A(x2), A(x1))
val result_7 = select(A(x3), A(x1), A(x2))
val result_8 = select(A(x1), A(x3))
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.collections.MutableList<(kotlin.Int..kotlin.Int?)>..kotlin.collections.List<(kotlin.Int..kotlin.Int?)>?)")!>result_1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.collections.MutableList<kotlin.Int>..kotlin.collections.List<kotlin.Int>?)")!>result_2<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.List<kotlin.Int>?")!>result_3<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.List<kotlin.Int>?")!>result_4<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(kotlin.collections.MutableList<(kotlin.Int..kotlin.Int?)>..kotlin.collections.List<(kotlin.Int..kotlin.Int?)>?)>")!>result_5<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<kotlin.collections.MutableList<kotlin.Int>>")!>result_6<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(kotlin.collections.MutableList<(kotlin.Int..kotlin.Int?)>..kotlin.collections.List<(kotlin.Int..kotlin.Int?)>?)>")!>result_7<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(kotlin.collections.MutableList<(kotlin.Int..kotlin.Int?)>..kotlin.collections.List<(kotlin.Int..kotlin.Int?)>?)>")!>result_8<!>
}
fun case_13() {
val x1 = Test.getList(10)
val x2: dynamic = null
val x3 = null as MutableList<Int>
val x4 = select(null as List<Int>, null)
val result_1 = select(x1, x2, x3, x4)
val result_2 = select(x2, x1)
val result_3 = select(x2, x1, x3)
val result_4 = select(x3, x2)
val result_5 = select(x4, x2)
val result_6 = select(x4, x3, x2)
val result_7 = select(A(x1), A(x2), A(x3), A(x4))
val result_8 = select(A(x2), A(x1))
val result_9 = select(A(x2), A(x1), A(x3))
val result_10 = select(A(x3), A(x2))
val result_11 = select(A(x4), A(x2))
val result_12 = select(A(x4), A(x3), A(x2))
<!DEBUG_INFO_EXPRESSION_TYPE("dynamic")!>result_1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("dynamic")!>result_2<!>
<!DEBUG_INFO_EXPRESSION_TYPE("dynamic")!>result_3<!>
<!DEBUG_INFO_EXPRESSION_TYPE("dynamic")!>result_4<!>
<!DEBUG_INFO_EXPRESSION_TYPE("dynamic")!>result_5<!>
<!DEBUG_INFO_EXPRESSION_TYPE("dynamic")!>result_6<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(kotlin.collections.MutableList<(kotlin.Int..kotlin.Int?)>..kotlin.collections.List<(kotlin.Int..kotlin.Int?)>?)>")!>result_7<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<dynamic>")!>result_8<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<dynamic>")!>result_9<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<kotlin.collections.MutableList<kotlin.Int>>")!>result_10<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<kotlin.collections.List<kotlin.Int>?>")!>result_11<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<dynamic>")!>result_12<!>
}
fun case_14() {
val x1 = Test.getRawList()
val x2 = null as List<Int>
val x3 = select(null as MutableList<Int>, null)
val result_1 = select(x1, x2)
val result_2 = select(x2, x1)
val result_3 = select(x2, x1, x3)
val result_4 = select(x3, x1)
val result_5 = select(A(x1), A(x2))
val result_6 = select(A(x2), A(x1))
val result_7 = select(A(x3), A(x1), A(x2))
val result_8 = select(A(x1), A(x3))
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.collections.List<kotlin.Any?>..kotlin.collections.List<kotlin.Any?>?)")!>result_1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.collections.List<kotlin.Any?>..kotlin.collections.List<kotlin.Any?>?)")!>result_2<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.List<kotlin.Any?>?")!>result_3<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.collections.MutableList<out kotlin.Any?>?..kotlin.collections.List<kotlin.Any?>?)")!>result_4<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<out (kotlin.collections.List<kotlin.Any?>..kotlin.collections.List<kotlin.Any?>?)>")!>result_5<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<out (kotlin.collections.List<kotlin.Any?>..kotlin.collections.List<kotlin.Any?>?)>")!>result_6<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<out kotlin.collections.List<kotlin.Any?>?>")!>result_7<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<out (kotlin.collections.MutableList<out kotlin.Any?>?..kotlin.collections.List<kotlin.Any?>?)>")!>result_8<!>
}
@@ -0,0 +1,273 @@
// !DIAGNOSTICS: -UNSUPPORTED -UNUSED_EXPRESSION -DEBUG_INFO_SMARTCAST -USELESS_CAST -UNUSED_PARAMETER -UNCHECKED_CAST -CAST_NEVER_SUCCEEDS -UNUSED_VARIABLE -UNREACHABLE_CODE -DEBUG_INFO_CONSTANT
// !LANGUAGE: +NewInference
// SKIP_TXT
// FILE: Test.java
import java.util.List;
public class Test {
public static B foo() { return null; }
public static <T> T bar() { return null; }
public static <T> T id(T x) { return null; }
public static <T> List<T> getList(T x) { return null; }
public static List getRawList() { return null; }
}
// FILE: main.kt
class A<T>(x: T)
class B
fun <T> select(vararg x: T): T = null as T
fun case_1() {
val x = Test.foo() // B!
val result_1 = select(A(x), A(B()))
val result_2 = select(A(B()), A(x), A(if (true) B() else null))
val result_3 = select(A(x), A(if (true) B() else null))
result_1
result_2
result_3
}
fun case_2() {
val x = Test.bar<Any>() // Any!
val y: Any? = null
val result = select(A(Any()), A(y), A(x))
result
}
fun <T> case_3() {
val x = Test.bar<T>() // T!
val y: T? = null
val result = select(A(y), A(x), A(null as T))
result
}
fun case_4() {
val x = Test.bar<Nothing>() // Nothing!
val y = null // Nothing?
val result = select(A(x), A(y), A(return))
result
}
class C<T, K, L>(x: T, y: K, z: L)
fun case_5() {
val x = Test.foo() // B!
val y: B? = null
val result_1 = select(C(x, B(), 10), C(B(), x, 10))
val result_2 = select(C(B(), x, y), C(x, B(), y), C(y, x, B()), C(x, y, B()), C(y, B(), x), C(B(), y, x))
result_1
result_2
}
fun case_6() {
val x1 = Test.bar<C<C<A<Float>, B, Int>, B, B>>() // C<C<A<Float>, B, Int>, B, B>!
val x2 = C(null as C<A<Float?>, B?, Int>?, Test.id(B()), B()) // C<C<A<Float?>, B?, Int>?, B?, B>
val x3 = C(C(A(Test.id(1f)), B(), Test.id(1)), Test.id(B()), B()) // C<C<A<Float!>, B, Int!>, B!, B>
val x4 = C(C(A(Test.id(3f)), null as B?, null as Int?), null as B?, null as B?) // C<C<A<Float?>?, B?, Int?>, B?, B?>
val x5 = C(Test.id(C(A(1f), Test.id(B()), 1)), B(), Test.id(B())) // C<C<A<Float>, B!, Int>!, B, B!>
val x6 = Test.id(C(select(C(Test.id(A(1f)), null as B?, null as Int?), null), Test.id(B()), null as B?)) // C<C<A<Float!>, B?, Int?>?, B!, B?>!
val x7 = C(C(Test.id(A(1f)), B(), 1), B(), B()) // C<C<A<Float>!, B, Int>, B, B>
val x8 = C(Test.id(C(null as A<Float?>?, B(), null as Int?)), null as B?, Test.id(B())) // C<C<A<Float?>?, B, Int?>, B?, B>
val x9 = null as C<C<A<Float>, B?, Int>, B, B>? // C<C<A<Float>, B?, Int>, B, B>?
val result_1 = select(x1, x2, x3, x4, x5, x6, x7, x8, x9)
val result_2 = select(x9, x8, x7, x6, x5, x4, x3, x2, x1)
val result_3 = select(x5, x7, x9, x3, x1, x2, x8, x4, x6)
result_1
result_2
result_3
}
fun case_7() {
val x0: Int = 1
val x1 = C(A(Test.id(x0)), B(), B())
val x2 = C(Test.id(A(1)), B(), B())
x1
x2
val result_5 = select(x1, x2)
result_5
}
fun case_8() {
val x1 = A(10)
val x2 = select(A(""), null)
val x3 = Test.id(A(null))
val result_1 = select(x1, x2, x3)
result_1
}
fun case_9() {
val x1 = A(A(10))
val x2 = A(select(A(""), null))
val x3 = A(Test.id(A('s')))
val result_1 = select(x1, x2, x3)
result_1
}
fun case_10() {
val x1 = 10
val x2 = select(10, null)
val x3 = Test.id(10)
val result_1 = select(x2, x1, x3)
val result_2 = select(x2, x3, x1)
val result_3 = select(x1, x2, x3)
val result_4 = select(x1, x3, x2)
val result_5 = select(x3, x2, x1)
val result_6 = select(x3, x1, x2)
result_1
result_2
result_3
result_4
result_5
result_6
}
fun <T> case_11(y: T) {
val x1 = Test.bar<T>() // T!
val x2 = select(y, null)
if (y != null) {
val x3 = Test.id(y) // T!
val result_1 = select(A(y), A(x1))
val result_2 = select(A(y), A(x1), A(x2))
val result_3 = select(A(y), A(x3), A(x2))
val result_4 = select(A(y as T), A(x1))
val result_5 = select(A(y as T), A(x1), A(x2))
val result_6 = select(A(y as T), A(x3), A(x2))
val result_7 = select(A(y as T), A(x1))
val result_8 = select(A(y as T), A(x3))
val result_9 = select(A(x3), A(y as T))
val result_10 = select(y, x1)
val result_11 = select(y, x2, x2)
val result_12 = select(y, x3, x2)
val result_13 = select(y as T, x1)
val result_14 = select(y as T, x1, x2)
val result_15 = select(y as T, x3, x2)
val result_16 = select(y as T, x1)
val result_17 = select(y as T, x3)
val result_18 = select(x3, y as T)
x1
x2
x3
y
result_1
result_2
result_3
result_4
result_5
result_6
result_7
result_8
result_9
result_10
result_11
result_12
result_13
result_14
result_15
result_16
result_17
result_18
}
}
fun case_12() {
val x1 = Test.getList(10)
val x2 = null as MutableList<Int>
val x3 = select(null as List<Int>, null)
val result_1 = select(x1, x2)
val result_2 = select(x2, x1)
val result_3 = select(x2, x1, x3)
val result_4 = select(x3, x1)
val result_5 = select(A(x1), A(x2))
val result_6 = select(A(x2), A(x1))
val result_7 = select(A(x3), A(x1), A(x2))
val result_8 = select(A(x1), A(x3))
result_1
result_2
result_3
result_4
result_5
result_6
result_7
result_8
}
fun case_13() {
val x1 = Test.getList(10)
val x2: dynamic = null
val x3 = null as MutableList<Int>
val x4 = select(null as List<Int>, null)
val result_1 = <!INAPPLICABLE_CANDIDATE!>select<!>(x1, x2, x3, x4)
val result_2 = <!INAPPLICABLE_CANDIDATE!>select<!>(x2, x1)
val result_3 = <!INAPPLICABLE_CANDIDATE!>select<!>(x2, x1, x3)
val result_4 = <!INAPPLICABLE_CANDIDATE!>select<!>(x3, x2)
val result_5 = <!INAPPLICABLE_CANDIDATE!>select<!>(x4, x2)
val result_6 = <!INAPPLICABLE_CANDIDATE!>select<!>(x4, x3, x2)
val result_7 = <!INAPPLICABLE_CANDIDATE!>select<!>(A(x1), <!INAPPLICABLE_CANDIDATE!>A<!>(x2), A(x3), A(x4))
val result_8 = <!INAPPLICABLE_CANDIDATE!>select<!>(<!INAPPLICABLE_CANDIDATE!>A<!>(x2), A(x1))
val result_9 = <!INAPPLICABLE_CANDIDATE!>select<!>(<!INAPPLICABLE_CANDIDATE!>A<!>(x2), A(x1), A(x3))
val result_10 = <!INAPPLICABLE_CANDIDATE!>select<!>(A(x3), <!INAPPLICABLE_CANDIDATE!>A<!>(x2))
val result_11 = <!INAPPLICABLE_CANDIDATE!>select<!>(A(x4), <!INAPPLICABLE_CANDIDATE!>A<!>(x2))
val result_12 = <!INAPPLICABLE_CANDIDATE!>select<!>(A(x4), A(x3), <!INAPPLICABLE_CANDIDATE!>A<!>(x2))
result_1
result_2
result_3
result_4
result_5
result_6
result_7
result_8
result_9
result_10
result_11
result_12
}
fun case_14() {
val x1 = Test.getRawList()
val x2 = null as List<Int>
val x3 = select(null as MutableList<Int>, null)
val result_1 = select(x1, x2)
val result_2 = select(x2, x1)
val result_3 = select(x2, x1, x3)
val result_4 = select(x3, x1)
val result_5 = select(A(x1), A(x2))
val result_6 = select(A(x2), A(x1))
val result_7 = select(A(x3), A(x1), A(x2))
val result_8 = select(A(x1), A(x3))
result_1
result_2
result_3
result_4
result_5
result_6
result_7
result_8
}
@@ -0,0 +1,273 @@
// !DIAGNOSTICS: -UNSUPPORTED -UNUSED_EXPRESSION -DEBUG_INFO_SMARTCAST -USELESS_CAST -UNUSED_PARAMETER -UNCHECKED_CAST -CAST_NEVER_SUCCEEDS -UNUSED_VARIABLE -UNREACHABLE_CODE -DEBUG_INFO_CONSTANT
// !LANGUAGE: +NewInference
// SKIP_TXT
// FILE: Test.java
import java.util.List;
public class Test {
public static B foo() { return null; }
public static <T> T bar() { return null; }
public static <T> T id(T x) { return null; }
public static <T> List<T> getList(T x) { return null; }
public static List getRawList() { return null; }
}
// FILE: main.kt
class A<T>(x: T)
class B
fun <T> select(vararg x: T): T = null as T
fun case_1() {
val x = Test.foo() // B!
val result_1 = select(A(x), A(B()))
val result_2 = select(A(B()), A(x), A(if (true) B() else null))
val result_3 = select(A(x), A(if (true) B() else null))
<!DEBUG_INFO_EXPRESSION_TYPE("A<(B..B?)>")!>result_1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(B..B?)>")!>result_2<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(B..B?)>")!>result_3<!>
}
fun case_2() {
val x = Test.bar<Any>() // Any!
val y: Any? = null
val result = select(A(Any()), A(y), A(x))
<!DEBUG_INFO_EXPRESSION_TYPE("A<(kotlin.Any..kotlin.Any?)>")!>result<!>
}
fun <T> case_3() {
val x = Test.bar<T>() // T!
val y: T? = null
val result = select(A(y), A(x), A(null as T))
<!DEBUG_INFO_EXPRESSION_TYPE("A<(T..T?)>")!>result<!>
}
fun case_4() {
val x = Test.bar<Nothing>() // Nothing!
val y = null // Nothing?
val result = select(A(x), A(y), A(return))
<!DEBUG_INFO_EXPRESSION_TYPE("A<(kotlin.Nothing..kotlin.Nothing?)>")!>result<!>
}
class C<T, K, L>(x: T, y: K, z: L)
fun case_5() {
val x = Test.foo() // B!
val y: B? = null
val result_1 = select(C(x, B(), 10), C(B(), x, 10))
val result_2 = select(C(B(), x, y), C(x, B(), y), C(y, x, B()), C(x, y, B()), C(y, B(), x), C(B(), y, x))
<!DEBUG_INFO_EXPRESSION_TYPE("C<(B..B?), B, kotlin.Int>")!>result_1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("C<(B..B?), (B..B?), (B..B?)>")!>result_2<!>
}
fun case_6() {
val x1 = Test.bar<C<C<A<Float>, B, Int>, B, B>>() // C<C<A<Float>, B, Int>, B, B>!
val x2 = C(null as C<A<Float?>, B?, Int>?, Test.id(B()), B()) // C<C<A<Float?>, B?, Int>?, B?, B>
val x3 = C(C(A(Test.id(1f)), B(), Test.id(1)), Test.id(B()), B()) // C<C<A<Float!>, B, Int!>, B!, B>
val x4 = C(C(A(Test.id(3f)), null as B?, null as Int?), null as B?, null as B?) // C<C<A<Float?>?, B?, Int?>, B?, B?>
val x5 = C(Test.id(C(A(1f), Test.id(B()), 1)), B(), Test.id(B())) // C<C<A<Float>, B!, Int>!, B, B!>
val x6 = Test.id(C(select(C(Test.id(A(1f)), null as B?, null as Int?), null), Test.id(B()), null as B?)) // C<C<A<Float!>, B?, Int?>?, B!, B?>!
val x7 = C(C(Test.id(A(1f)), B(), 1), B(), B()) // C<C<A<Float>!, B, Int>, B, B>
val x8 = C(Test.id(C(null as A<Float?>?, B(), null as Int?)), null as B?, Test.id(B())) // C<C<A<Float?>?, B, Int?>, B?, B>
val x9 = null as C<C<A<Float>, B?, Int>, B, B>? // C<C<A<Float>, B?, Int>, B, B>?
val result_1 = select(x1, x2, x3, x4, x5, x6, x7, x8, x9)
val result_2 = select(x9, x8, x7, x6, x5, x4, x3, x2, x1)
val result_3 = select(x5, x7, x9, x3, x1, x2, x8, x4, x6)
<!DEBUG_INFO_EXPRESSION_TYPE("C<out C<out A<(kotlin.Float..kotlin.Float?)>?, (B..B?), (kotlin.Int..kotlin.Int?)>?, (B..B?), (B..B?)>?")!>result_1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("C<out C<out A<(kotlin.Float..kotlin.Float?)>?, (B..B?), (kotlin.Int..kotlin.Int?)>?, (B..B?), (B..B?)>?")!>result_2<!>
<!DEBUG_INFO_EXPRESSION_TYPE("C<out C<out A<(kotlin.Float..kotlin.Float?)>?, (B..B?), (kotlin.Int..kotlin.Int?)>?, (B..B?), (B..B?)>?")!>result_3<!>
}
fun case_7() {
val x0: Int = 1
val x1 = C(A(Test.id(x0)), B(), B())
val x2 = C(Test.id(A(1)), B(), B())
<!DEBUG_INFO_EXPRESSION_TYPE("C<A<(kotlin.Int..kotlin.Int?)>, B, B>")!>x1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("C<(A<kotlin.Int>..A<kotlin.Int>?), B, B>")!>x2<!>
val result_5 = select(x1, x2)
<!DEBUG_INFO_EXPRESSION_TYPE("C<A<(kotlin.Int..kotlin.Int?)>, B, B>")!>result_5<!>
}
fun case_8() {
val x1 = A(10)
val x2 = select(A(""), null)
val x3 = Test.id(A(null))
val result_1 = select(x1, x2, x3)
<!DEBUG_INFO_EXPRESSION_TYPE("A<out {Comparable<{Int & String}> & java.io.Serializable}?>?")!>result_1<!>
}
fun case_9() {
val x1 = A(A(10))
val x2 = A(select(A(""), null))
val x3 = A(Test.id(A('s')))
val result_1 = select(x1, x2, x3)
<!DEBUG_INFO_EXPRESSION_TYPE("A<out A<out {Comparable<{Char & Int & String}> & java.io.Serializable}>?>")!>result_1<!>
}
fun case_10() {
val x1 = 10
val x2 = select(10, null)
val x3 = Test.id(10)
val result_1 = select(x2, x1, x3)
val result_2 = select(x2, x3, x1)
val result_3 = select(x1, x2, x3)
val result_4 = select(x1, x3, x2)
val result_5 = select(x3, x2, x1)
val result_6 = select(x3, x1, x2)
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int?")!>result_1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int?")!>result_2<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int?")!>result_3<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int?")!>result_4<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int?")!>result_5<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int?")!>result_6<!>
}
fun <T> case_11(y: T) {
val x1 = Test.bar<T>() // T!
val x2 = select(y, null)
if (y != null) {
val x3 = Test.id(y) // T!
val result_1 = select(A(y), A(x1))
val result_2 = select(A(y), A(x1), A(x2))
val result_3 = select(A(y), A(x3), A(x2))
val result_4 = select(A(y as T), A(x1))
val result_5 = select(A(y as T), A(x1), A(x2))
val result_6 = select(A(y as T), A(x3), A(x2))
val result_7 = select(A(y as T), A(x1))
val result_8 = select(A(y as T), A(x3))
val result_9 = select(A(x3), A(y as T))
val result_10 = select(y, x1)
val result_11 = select(y, x2, x2)
val result_12 = select(y, x3, x2)
val result_13 = select(y as T, x1)
val result_14 = select(y as T, x1, x2)
val result_15 = select(y as T, x3, x2)
val result_16 = select(y as T, x1)
val result_17 = select(y as T, x3)
val result_18 = select(x3, y as T)
<!DEBUG_INFO_EXPRESSION_TYPE("(T..T?)")!>x1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("T?")!>x2<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(T!!..T?)")!>x3<!>
<!DEBUG_INFO_EXPRESSION_TYPE("T & T!!")!>y<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<out (T..T?)>")!>result_1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<out T?>")!>result_2<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(T!!..T?)>")!>result_3<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<T>")!>result_4<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(T..T?)>")!>result_5<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(T!!..T?)>")!>result_6<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<T>")!>result_7<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<T>")!>result_8<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(T!!..T?)>")!>result_9<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(T..T?)")!>result_10<!>
<!DEBUG_INFO_EXPRESSION_TYPE("T?")!>result_11<!>
<!DEBUG_INFO_EXPRESSION_TYPE("T?")!>result_12<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(T..T?)")!>result_13<!>
<!DEBUG_INFO_EXPRESSION_TYPE("T?")!>result_14<!>
<!DEBUG_INFO_EXPRESSION_TYPE("T?")!>result_15<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(T..T?)")!>result_16<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(T..T?)")!>result_17<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(T..T?)")!>result_18<!>
}
}
fun case_12() {
val x1 = Test.getList(10)
val x2 = null as MutableList<Int>
val x3 = select(null as List<Int>, null)
val result_1 = select(x1, x2)
val result_2 = select(x2, x1)
val result_3 = select(x2, x1, x3)
val result_4 = select(x3, x1)
val result_5 = select(A(x1), A(x2))
val result_6 = select(A(x2), A(x1))
val result_7 = select(A(x3), A(x1), A(x2))
val result_8 = select(A(x1), A(x3))
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.collections.MutableList<(kotlin.Int..kotlin.Int?)>..kotlin.collections.List<(kotlin.Int..kotlin.Int?)>?)")!>result_1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.collections.MutableList<kotlin.Int>..kotlin.collections.List<kotlin.Int>?)")!>result_2<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.List<(kotlin.Int..kotlin.Int?)>?")!>result_3<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.List<kotlin.Int>?")!>result_4<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(kotlin.collections.MutableList<(kotlin.Int..kotlin.Int?)>..kotlin.collections.List<(kotlin.Int..kotlin.Int?)>?)>")!>result_5<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<kotlin.collections.MutableList<kotlin.Int>>")!>result_6<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(kotlin.collections.MutableList<(kotlin.Int..kotlin.Int?)>..kotlin.collections.List<(kotlin.Int..kotlin.Int?)>?)>")!>result_7<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<(kotlin.collections.MutableList<(kotlin.Int..kotlin.Int?)>..kotlin.collections.List<(kotlin.Int..kotlin.Int?)>?)>")!>result_8<!>
}
fun case_13() {
val x1 = Test.getList(10)
val x2: dynamic = null
val x3 = null as MutableList<Int>
val x4 = select(null as List<Int>, null)
val result_1 = select(x1, x2, x3, x4)
val result_2 = select(x2, x1)
val result_3 = select(x2, x1, x3)
val result_4 = select(x3, x2)
val result_5 = select(x4, x2)
val result_6 = select(x4, x3, x2)
val result_7 = select(A(x1), A(x2), A(x3), A(x4))
val result_8 = select(A(x2), A(x1))
val result_9 = select(A(x2), A(x1), A(x3))
val result_10 = select(A(x3), A(x2))
val result_11 = select(A(x4), A(x2))
val result_12 = select(A(x4), A(x3), A(x2))
<!DEBUG_INFO_EXPRESSION_TYPE("dynamic")!>result_1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("dynamic")!>result_2<!>
<!DEBUG_INFO_EXPRESSION_TYPE("dynamic")!>result_3<!>
<!DEBUG_INFO_EXPRESSION_TYPE("dynamic")!>result_4<!>
<!DEBUG_INFO_EXPRESSION_TYPE("dynamic")!>result_5<!>
<!DEBUG_INFO_EXPRESSION_TYPE("dynamic")!>result_6<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<dynamic>")!>result_7<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<dynamic>")!>result_8<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<dynamic>")!>result_9<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<dynamic>")!>result_10<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<dynamic>")!>result_11<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<dynamic>")!>result_12<!>
}
fun case_14() {
val x1 = Test.getRawList()
val x2 = null as List<Int>
val x3 = select(null as MutableList<Int>, null)
val result_1 = select(x1, x2)
val result_2 = select(x2, x1)
val result_3 = select(x2, x1, x3)
val result_4 = select(x3, x1)
val result_5 = select(A(x1), A(x2))
val result_6 = select(A(x2), A(x1))
val result_7 = select(A(x3), A(x1), A(x2))
val result_8 = select(A(x1), A(x3))
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.collections.List<kotlin.Any?>..kotlin.collections.List<*>?)")!>result_1<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.collections.List<kotlin.Any?>..kotlin.collections.List<*>?)")!>result_2<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.collections.List<kotlin.Any?>?..kotlin.collections.List<*>?)")!>result_3<!>
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.collections.MutableList<out kotlin.Any?>?..kotlin.collections.List<*>?)")!>result_4<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<out (kotlin.collections.List<kotlin.Any?>..kotlin.collections.List<*>?)>")!>result_5<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<out (kotlin.collections.List<kotlin.Any?>..kotlin.collections.List<*>?)>")!>result_6<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<out (kotlin.collections.List<kotlin.Any?>?..kotlin.collections.List<*>?)>")!>result_7<!>
<!DEBUG_INFO_EXPRESSION_TYPE("A<out (kotlin.collections.MutableList<out kotlin.Any?>?..kotlin.collections.List<*>?)>")!>result_8<!>
}
@@ -11203,6 +11203,16 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/doNotInferFromBoundsOnly.kt");
}
@TestMetadata("flexibilityInCommonSuperTypeCalculation.kt")
public void testFlexibilityInCommonSuperTypeCalculation() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/flexibilityInCommonSuperTypeCalculation.kt");
}
@TestMetadata("flexibilityInCommonSuperTypeCalculation.ni.kt")
public void testFlexibilityInCommonSuperTypeCalculation_ni() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/flexibilityInCommonSuperTypeCalculation.ni.kt");
}
@TestMetadata("intersectUpperBounds.kt")
public void testIntersectUpperBounds() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/intersectUpperBounds.kt");
@@ -11198,6 +11198,16 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/doNotInferFromBoundsOnly.kt");
}
@TestMetadata("flexibilityInCommonSuperTypeCalculation.kt")
public void testFlexibilityInCommonSuperTypeCalculation() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/flexibilityInCommonSuperTypeCalculation.kt");
}
@TestMetadata("flexibilityInCommonSuperTypeCalculation.ni.kt")
public void testFlexibilityInCommonSuperTypeCalculation_ni() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/flexibilityInCommonSuperTypeCalculation.ni.kt");
}
@TestMetadata("intersectUpperBounds.kt")
public void testIntersectUpperBounds() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/upperBounds/intersectUpperBounds.kt");
@@ -580,3 +580,28 @@ object AbstractNullabilityChecker {
return isEqualTypeConstructors(type.typeConstructor(), end)
}
}
object AbstractFlexibilityChecker {
fun TypeSystemCommonSuperTypesContext.hasDifferentFlexibilityAtDepth(types: Collection<KotlinTypeMarker>): Boolean {
if (types.isEmpty()) return false
if (hasDifferentFlexibility(types)) return true
for (i in 0 until types.first().argumentsCount()) {
val typeArgumentForOtherTypes = types.mapNotNull {
if (it.argumentsCount() > i && !it.getArgument(i).isStarProjection()) it.getArgument(i).getType() else null
}
if (hasDifferentFlexibilityAtDepth(typeArgumentForOtherTypes)) return true
}
return false
}
private fun TypeSystemCommonSuperTypesContext.hasDifferentFlexibility(types: Collection<KotlinTypeMarker>): Boolean {
val firstType = types.first()
if (types.all { it === firstType }) return false
return !types.all { it.isFlexible() } && !types.all { !it.isFlexible() }
}
}