NI: Discard definitely not-null types inside invariant positions during inference process

^KT-36816 Fixed
This commit is contained in:
Victor Petukhov
2020-02-18 19:09:46 +03:00
parent 36f4b6daf3
commit 748a326104
8 changed files with 102 additions and 3 deletions
@@ -10695,6 +10695,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/constraints"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
}
@TestMetadata("approximationWithDefNotNullInInvPositionDuringInference.kt")
public void testApproximationWithDefNotNullInInvPositionDuringInference() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/constraints/approximationWithDefNotNullInInvPositionDuringInference.kt");
}
@TestMetadata("constraintFromVariantTypeWithNestedProjection.kt")
public void testConstraintFromVariantTypeWithNestedProjection() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/constraints/constraintFromVariantTypeWithNestedProjection.kt");
@@ -83,7 +83,10 @@ open class TypeApproximatorConfiguration {
override val typeVariable: (TypeVariableTypeConstructorMarker) -> Boolean get() = { true }
}
object IncorporationConfiguration : TypeApproximatorConfiguration.AbstractCapturedTypesApproximation(FOR_INCORPORATION)
object IncorporationConfiguration : TypeApproximatorConfiguration.AbstractCapturedTypesApproximation(FOR_INCORPORATION) {
override val definitelyNotNullTypeInInvariantPosition: Boolean get() = false
}
object SubtypeCapturedTypesApproximation : TypeApproximatorConfiguration.AbstractCapturedTypesApproximation(FOR_SUBTYPING)
object CapturedAndIntegerLiteralsTypesApproximation : TypeApproximatorConfiguration.AbstractCapturedTypesApproximation(FROM_EXPRESSION) {
override val integerLiteralType: Boolean get() = true
@@ -0,0 +1,24 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
// Issues: KT-36816
interface Parent<T>
class Foo<K>(x: K?): Parent<K> {}
class Bar<T>(x: T): Parent<T> {}
fun <R> select(vararg x: R) = x[0]
fun <S> main(x: S) {
select(Foo(x), Bar(x))
}
inline fun <R> test(transform: () -> R) {}
class Inv<T>(x: T?) {}
fun <K> foo(x: K) {
test { Inv(x) }
}
@@ -0,0 +1,24 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
// Issues: KT-36816
interface Parent<T>
class Foo<K>(x: K?): Parent<K> {}
class Bar<T>(x: T): Parent<T> {}
fun <R> select(vararg x: R) = x[0]
fun <S> main(x: S) {
<!DEBUG_INFO_EXPRESSION_TYPE("Parent<S>")!>select(Foo(x), Bar(x))<!>
}
inline fun <R> test(transform: () -> R) {}
class Inv<T>(x: T?) {}
fun <K> foo(x: K) {
test { <!DEBUG_INFO_EXPRESSION_TYPE("Inv<K>")!>Inv(x)<!> }
}
@@ -0,0 +1,33 @@
package
public fun </*0*/ K> foo(/*0*/ x: K): kotlin.Unit
public fun </*0*/ S> main(/*0*/ x: S): kotlin.Unit
public fun </*0*/ R> select(/*0*/ vararg x: R /*kotlin.Array<out R>*/): R
public inline fun </*0*/ R> test(/*0*/ transform: () -> R): kotlin.Unit
public final class Bar</*0*/ T> : Parent<T> {
public constructor Bar</*0*/ T>(/*0*/ x: T)
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 final class Foo</*0*/ K> : Parent<K> {
public constructor Foo</*0*/ K>(/*0*/ 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 final class Inv</*0*/ T> {
public constructor Inv</*0*/ T>(/*0*/ x: T?)
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 interface Parent</*0*/ T> {
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
}
@@ -169,8 +169,8 @@ fun <T> case_11(y: T) {
<!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>")!>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<!>
@@ -10702,6 +10702,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/constraints"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
}
@TestMetadata("approximationWithDefNotNullInInvPositionDuringInference.kt")
public void testApproximationWithDefNotNullInInvPositionDuringInference() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/constraints/approximationWithDefNotNullInInvPositionDuringInference.kt");
}
@TestMetadata("constraintFromVariantTypeWithNestedProjection.kt")
public void testConstraintFromVariantTypeWithNestedProjection() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/constraints/constraintFromVariantTypeWithNestedProjection.kt");
@@ -10697,6 +10697,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/constraints"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
}
@TestMetadata("approximationWithDefNotNullInInvPositionDuringInference.kt")
public void testApproximationWithDefNotNullInInvPositionDuringInference() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/constraints/approximationWithDefNotNullInInvPositionDuringInference.kt");
}
@TestMetadata("constraintFromVariantTypeWithNestedProjection.kt")
public void testConstraintFromVariantTypeWithNestedProjection() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/constraints/constraintFromVariantTypeWithNestedProjection.kt");