Capture notnullable type if type variable is nullable
This commit is contained in:
+4
-10
@@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
fun <T: Any> bar(a: Array<T>): Array<T?> = null!!
|
fun <T: Any> bar(a: Array<T>): Array<T?> = null!!
|
||||||
|
|
||||||
fun test1(a: Array<Int>) {
|
fun test1(a: Array<out Int>) {
|
||||||
val r: Array<Int?> = bar(a)
|
val r: Array<out Int?> = bar(a)
|
||||||
val t = bar(a)
|
val t = bar(a)
|
||||||
t checkType { it : _<Array<Int?>> }
|
t checkType { it : _<Array<out Int?>> }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T: Any> foo(l: Array<T>): Array<Array<T?>> = null!!
|
fun <T: Any> foo(l: Array<T>): Array<Array<T?>> = null!!
|
||||||
@@ -15,10 +15,4 @@ fun test2(a: Array<out Int>) {
|
|||||||
val r: Array<out Array<out Int?>> = foo(a)
|
val r: Array<out Array<out Int?>> = foo(a)
|
||||||
val t = foo(a)
|
val t = foo(a)
|
||||||
t checkType { it : _<Array<out Array<out Int?>>> }
|
t checkType { it : _<Array<out Array<out Int?>>> }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun test3(a: Array<in Int>) {
|
|
||||||
val r: Array<out Array<in Int?>> = foo(a)
|
|
||||||
val t = foo(a)
|
|
||||||
t checkType { it : _<Array<out Array<in Int?>>> }
|
|
||||||
}
|
|
||||||
+1
-2
@@ -2,6 +2,5 @@ package
|
|||||||
|
|
||||||
internal fun </*0*/ T : kotlin.Any> bar(/*0*/ a: kotlin.Array<T>): kotlin.Array<T?>
|
internal fun </*0*/ T : kotlin.Any> bar(/*0*/ a: kotlin.Array<T>): kotlin.Array<T?>
|
||||||
internal fun </*0*/ T : kotlin.Any> foo(/*0*/ l: kotlin.Array<T>): kotlin.Array<kotlin.Array<T?>>
|
internal fun </*0*/ T : kotlin.Any> foo(/*0*/ l: kotlin.Array<T>): kotlin.Array<kotlin.Array<T?>>
|
||||||
internal fun test1(/*0*/ a: kotlin.Array<kotlin.Int>): kotlin.Unit
|
internal fun test1(/*0*/ a: kotlin.Array<out kotlin.Int>): kotlin.Unit
|
||||||
internal fun test2(/*0*/ a: kotlin.Array<out kotlin.Int>): kotlin.Unit
|
internal fun test2(/*0*/ a: kotlin.Array<out kotlin.Int>): kotlin.Unit
|
||||||
internal fun test3(/*0*/ a: kotlin.Array<in kotlin.Int>): kotlin.Unit
|
|
||||||
|
|||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
// !CHECK_TYPE
|
||||||
|
|
||||||
|
fun <T : Any> Array<T?>.filterNotNull(): List<T> = throw Exception()
|
||||||
|
|
||||||
|
fun test1(a: Array<out Int?>) {
|
||||||
|
val list = a.filterNotNull()
|
||||||
|
list checkType { it : _<List<Int>> }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test2(vararg a: Int?) {
|
||||||
|
val list = a.filterNotNull()
|
||||||
|
list checkType { it : _<List<Int>> }
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
internal fun test1(/*0*/ a: kotlin.Array<out kotlin.Int?>): kotlin.Unit
|
||||||
|
internal fun test2(/*0*/ vararg a: kotlin.Int? /*kotlin.Array<out kotlin.Int?>*/): kotlin.Unit
|
||||||
|
internal fun </*0*/ T : kotlin.Any> kotlin.Array<T?>.filterNotNull(): kotlin.List<T>
|
||||||
@@ -5106,6 +5106,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("captureFromNullableTypeVariable.kt")
|
||||||
|
public void testCaptureFromNullableTypeVariable() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/capturedTypes/captureFromNullableTypeVariable.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("captureTypeOnlyOnTopLevel.kt")
|
@TestMetadata("captureTypeOnlyOnTopLevel.kt")
|
||||||
public void testCaptureTypeOnlyOnTopLevel() throws Exception {
|
public void testCaptureTypeOnlyOnTopLevel() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/capturedTypes/captureTypeOnlyOnTopLevel.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/capturedTypes/captureTypeOnlyOnTopLevel.kt");
|
||||||
|
|||||||
+7
-1
@@ -380,7 +380,13 @@ public class ConstraintSystemImpl : ConstraintSystem {
|
|||||||
constraintPosition: ConstraintPosition
|
constraintPosition: ConstraintPosition
|
||||||
) {
|
) {
|
||||||
val typeBounds = getTypeBounds(parameterType)
|
val typeBounds = getTypeBounds(parameterType)
|
||||||
val capturedType = createCapturedType(constrainingTypeProjection)
|
val typeProjection = if (parameterType.isMarkedNullable()) {
|
||||||
|
TypeProjectionImpl(constrainingTypeProjection.getProjectionKind(), TypeUtils.makeNotNullable(constrainingTypeProjection.getType()))
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
constrainingTypeProjection
|
||||||
|
}
|
||||||
|
val capturedType = createCapturedType(typeProjection)
|
||||||
typeBounds.addBound(EXACT_BOUND, capturedType, constraintPosition)
|
typeBounds.addBound(EXACT_BOUND, capturedType, constraintPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user