[NI] Add constraint K <: T from constraint K <: CapturedType(in T)

#KT-33263 Fixed
This commit is contained in:
Dmitriy Novozhilov
2019-12-23 17:10:20 +03:00
parent b54169d312
commit 51424ec598
7 changed files with 104 additions and 4 deletions
@@ -9918,6 +9918,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
runTest("compiler/testData/diagnostics/tests/inference/kt32434.kt");
}
@TestMetadata("kt33263.kt")
public void testKt33263() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt33263.kt");
}
@TestMetadata("kt6175.kt")
public void testKt6175() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt6175.kt");
@@ -28,10 +28,20 @@ abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheck
abstract fun addLowerConstraint(typeVariable: TypeConstructorMarker, subType: KotlinTypeMarker)
override fun getLowerCapturedTypePolicy(subType: SimpleTypeMarker, superType: CapturedTypeMarker): LowerCapturedTypePolicy = when {
isMyTypeVariable(subType) -> LowerCapturedTypePolicy.SKIP_LOWER
subType.contains { it.anyBound(this::isMyTypeVariable) } -> LowerCapturedTypePolicy.CHECK_ONLY_LOWER
else -> LowerCapturedTypePolicy.CHECK_SUBTYPE_AND_LOWER
override fun getLowerCapturedTypePolicy(subType: SimpleTypeMarker, superType: CapturedTypeMarker): LowerCapturedTypePolicy {
return when {
isMyTypeVariable(subType) -> {
val projection = superType.typeConstructorProjection()
val type = projection.getType().asSimpleType()
if (projection.getVariance() == TypeVariance.IN && type != null && isMyTypeVariable(type)) {
LowerCapturedTypePolicy.CHECK_ONLY_LOWER
} else {
LowerCapturedTypePolicy.SKIP_LOWER
}
}
subType.contains { it.anyBound(this::isMyTypeVariable) } -> LowerCapturedTypePolicy.CHECK_ONLY_LOWER
else -> LowerCapturedTypePolicy.CHECK_SUBTYPE_AND_LOWER
}
}
/**
@@ -0,0 +1,23 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
// ISSUE: KT-33263
class A
class Foo<U>
class Bar<R>
fun <T> Foo<in T>.create(): Bar<in T> = null!!//Bar()
//fun <T> Foo<in T>.create(): Bar<T> = null!!//Bar()
fun <K> convert(bar: Bar<in K>): Bar<K> = null!!//Bar()
fun test(x: Any) {}
fun take(x: Bar<A>) {}
fun test_1(foo: Foo<A>) {
// convert(foo.create())
convert(foo.create())
}
fun test_2(foo: Foo<A>) {
test(convert(foo.create()))
}
@@ -0,0 +1,23 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
// ISSUE: KT-33263
class A
class Foo<U>
class Bar<R>
fun <T> Foo<in T>.create(): Bar<in T> = null!!//Bar()
//fun <T> Foo<in T>.create(): Bar<T> = null!!//Bar()
fun <K> convert(bar: Bar<in K>): Bar<K> = null!!//Bar()
fun test(x: Any) {}
fun take(x: Bar<A>) {}
fun test_1(foo: Foo<A>) {
// convert(foo.create())
<!DEBUG_INFO_EXPRESSION_TYPE("Bar<A>")!>convert(foo.create())<!>
}
fun test_2(foo: Foo<A>) {
test(convert(foo.create()))
}
@@ -0,0 +1,29 @@
package
public fun </*0*/ K> convert(/*0*/ bar: Bar<in K>): Bar<K>
public fun take(/*0*/ x: Bar<A>): kotlin.Unit
public fun test(/*0*/ x: kotlin.Any): kotlin.Unit
public fun test_1(/*0*/ foo: Foo<A>): kotlin.Unit
public fun test_2(/*0*/ foo: Foo<A>): kotlin.Unit
public fun </*0*/ T> Foo<in T>.create(): Bar<in T>
public final class A {
public constructor A()
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 Bar</*0*/ R> {
public constructor Bar</*0*/ R>()
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*/ U> {
public constructor Foo</*0*/ U>()
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
}
@@ -9925,6 +9925,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
runTest("compiler/testData/diagnostics/tests/inference/kt32434.kt");
}
@TestMetadata("kt33263.kt")
public void testKt33263() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt33263.kt");
}
@TestMetadata("kt6175.kt")
public void testKt6175() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt6175.kt");
@@ -9920,6 +9920,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/inference/kt32434.kt");
}
@TestMetadata("kt33263.kt")
public void testKt33263() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt33263.kt");
}
@TestMetadata("kt6175.kt")
public void testKt6175() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/kt6175.kt");