Mark projection of a nullable captured type as not null during simplification constrains with it and a nullable type variable
^KT-41913 Fixed
This commit is contained in:
+5
@@ -10684,6 +10684,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/notApproximateWhenCopyDescriptors.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nullableCaptruredTypeAgainstNullableVariable.kt")
|
||||
public void testNullableCaptruredTypeAgainstNullableVariable() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/nullableCaptruredTypeAgainstNullableVariable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overApproximationForInCaptured.kt")
|
||||
public void testOverApproximationForInCaptured() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/overApproximationForInCaptured.kt");
|
||||
|
||||
+3
-7
@@ -209,20 +209,16 @@ abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheck
|
||||
if (typeVariable.isMarkedNullable()) {
|
||||
val typeVariableTypeConstructor = typeVariable.typeConstructor()
|
||||
val subTypeConstructor = subType.typeConstructor()
|
||||
|
||||
if (
|
||||
val resultType = if (
|
||||
!subTypeConstructor.isTypeVariable() &&
|
||||
typeVariableTypeConstructor.isTypeVariable() &&
|
||||
(typeVariableTypeConstructor as TypeVariableTypeConstructorMarker).isContainedInInvariantOrContravariantPositions()
|
||||
) {
|
||||
if (subType.isCapturedType()) {
|
||||
(subType as CapturedTypeMarker).withNotNullProjection()
|
||||
} else {
|
||||
subType.withNullability(false)
|
||||
}
|
||||
subType.withNullability(false)
|
||||
} else {
|
||||
subType.makeDefinitelyNotNullOrNotNull()
|
||||
}
|
||||
if (resultType is CapturedTypeMarker) resultType.withNotNullProjection() else resultType
|
||||
} else subType
|
||||
|
||||
is FlexibleTypeMarker -> {
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// !DIAGNOSTICS: -CAST_NEVER_SUCCEEDS -REDUNDANT_PROJECTION
|
||||
|
||||
// FILE: Foo.java
|
||||
public class Foo<L> extends Bar<L> {
|
||||
public Foo(L x) {
|
||||
super(x);
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun <T : Any> Bar<T>.foo(): T = null as T
|
||||
fun <T : Any> Bar<T?>.bar(): T = null as T
|
||||
fun <T : Any> Foo<T>.boo1(): T = null as T
|
||||
fun <T : Any> Foo<T?>.boo2(): T = null as T
|
||||
|
||||
open class Bar<out K>(val x: K)
|
||||
|
||||
fun main(x: Foo<out Number?>, y: Bar<out Number?>, z1: Foo<out Number>, z2: Bar<out Number>) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>x.foo()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number")!>x.bar()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number?")!>x.boo1()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>x.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>boo2<!>()<!>
|
||||
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>y.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>foo<!>()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number")!>y.bar()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>y.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>boo1<!>()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>y.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>boo2<!>()<!>
|
||||
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.Number..kotlin.Number?)")!>z1.foo()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number")!>z1.bar()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number")!>z1.boo1()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>z1.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>boo2<!>()<!>
|
||||
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number")!>z2.foo()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Number")!>z2.bar()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>z2.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>boo1<!>()<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Type is unknown")!>z2.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>boo2<!>()<!>
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package
|
||||
|
||||
public fun main(/*0*/ x: Foo<out kotlin.Number?>, /*1*/ y: Bar<out kotlin.Number?>, /*2*/ z1: Foo<out kotlin.Number>, /*3*/ z2: Bar<out kotlin.Number>): kotlin.Unit
|
||||
public fun </*0*/ T : kotlin.Any> Bar<T?>.bar(): T
|
||||
public fun </*0*/ T : kotlin.Any> Foo<T>.boo1(): T
|
||||
public fun </*0*/ T : kotlin.Any> Foo<T?>.boo2(): T
|
||||
public fun </*0*/ T : kotlin.Any> Bar<T>.foo(): T
|
||||
|
||||
public open class Bar</*0*/ out K> {
|
||||
public constructor Bar</*0*/ out K>(/*0*/ x: K)
|
||||
public final val x: K
|
||||
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 open class Foo</*0*/ L : kotlin.Any!> : Bar<L!> {
|
||||
public constructor Foo</*0*/ L : kotlin.Any!>(/*0*/ x: L!)
|
||||
public final override /*1*/ /*fake_override*/ val x: L!
|
||||
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
|
||||
}
|
||||
@@ -10691,6 +10691,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/notApproximateWhenCopyDescriptors.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nullableCaptruredTypeAgainstNullableVariable.kt")
|
||||
public void testNullableCaptruredTypeAgainstNullableVariable() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/nullableCaptruredTypeAgainstNullableVariable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overApproximationForInCaptured.kt")
|
||||
public void testOverApproximationForInCaptured() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/overApproximationForInCaptured.kt");
|
||||
|
||||
Generated
+5
@@ -10686,6 +10686,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/notApproximateWhenCopyDescriptors.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nullableCaptruredTypeAgainstNullableVariable.kt")
|
||||
public void testNullableCaptruredTypeAgainstNullableVariable() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/nullableCaptruredTypeAgainstNullableVariable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overApproximationForInCaptured.kt")
|
||||
public void testOverApproximationForInCaptured() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/overApproximationForInCaptured.kt");
|
||||
|
||||
Reference in New Issue
Block a user