[NI] Approximate captured types when we resolve type variable TO_SUPER.

This commit is contained in:
Stanislav Erokhin
2017-04-07 15:32:37 +03:00
parent 53caa84db9
commit 6e24b0f89d
6 changed files with 57 additions and 2 deletions
@@ -58,7 +58,6 @@ class ResultTypeResolver(
*
* To fix this problem when we fix variable, we will approximate captured types before fixation.
*
* todo: may be for TO_SUPER direction we should do the same
*/
return typeApproximator.approximateToSuperType(commonSupertype, TypeApproximatorConfiguration.CapturedTypesApproximation) ?: commonSupertype
@@ -68,7 +67,9 @@ class ResultTypeResolver(
// direction == TO_SUPER or there is no LOWER bounds
val upperConstraints = variableWithConstraints.constraints.filter { it.kind == ConstraintKind.UPPER && c.isProperType(it.type) }
if (upperConstraints.isNotEmpty()) {
return intersectTypes(upperConstraints.map { it.type })
val upperType = intersectTypes(upperConstraints.map { it.type })
return typeApproximator.approximateToSubType(upperType, TypeApproximatorConfiguration.CapturedTypesApproximation) ?: upperType
}
return null
@@ -0,0 +1,13 @@
// FILE: 1.kt
fun <S> Array<S>.plus(): Array<S> {
val result = Arrays.copyOf(this, 3)
// result type is Array<(out) (S&Any)!>!
return result
}
// FILE: Arrays.java
public class Arrays {
public static <T> T[] copyOf(T[] original, int newLength) {
return (T[]) null;
}
}
@@ -0,0 +1,13 @@
package
public fun </*0*/ S> kotlin.Array<S>.plus(): kotlin.Array<S>
public open class Arrays {
public constructor Arrays()
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*/ T : kotlin.Any!> copyOf(/*0*/ original: kotlin.Array<(out) T!>!, /*1*/ newLength: kotlin.Int): kotlin.Array<(out) T!>!
}
@@ -0,0 +1,11 @@
fun <S : Any> foo(x: Array<out S?>, y: Array<in S?>) {
val xo = outA(x)
val yo = inA(y)
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>f<!>: Array<S> = xo
<!UNUSED_VALUE!>f =<!> yo
}
fun <X : Any> outA(<!UNUSED_PARAMETER!>x<!>: Array<out X?>): Array<X> = TODO()
fun <Y : Any> inA(<!UNUSED_PARAMETER!>x<!>: Array<in Y?>): Array<Y> = TODO()
@@ -0,0 +1,5 @@
package
public fun </*0*/ S : kotlin.Any> foo(/*0*/ x: kotlin.Array<out S?>, /*1*/ y: kotlin.Array<in S?>): kotlin.Unit
public fun </*0*/ Y : kotlin.Any> inA(/*0*/ x: kotlin.Array<in Y?>): kotlin.Array<Y>
public fun </*0*/ X : kotlin.Any> outA(/*0*/ x: kotlin.Array<out X?>): kotlin.Array<X>
@@ -10048,6 +10048,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("flexibleTypesAsUpperBound.kt")
public void testFlexibleTypesAsUpperBound() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/flexibleTypesAsUpperBound.kt");
doTest(fileName);
}
@TestMetadata("functionPlaceholderError.kt")
public void testFunctionPlaceholderError() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/functionPlaceholderError.kt");
@@ -10162,6 +10168,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("nullableTypeArgumentWithNotNullUpperBound.kt")
public void testNullableTypeArgumentWithNotNullUpperBound() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/nullableTypeArgumentWithNotNullUpperBound.kt");
doTest(fileName);
}
@TestMetadata("nullableUpperBound.kt")
public void testNullableUpperBound() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/nullableUpperBound.kt");