[NI] Take into account captured types for type depth computation

It's needed to estimate the count of steps for type approximation algorithm.
 After the estimated count of steps, we consider such type recursive and this
 algorithm returns some default value

 #KT-28598 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2018-12-04 10:54:41 +03:00
parent ddb4e8b128
commit 383c2d1bff
5 changed files with 62 additions and 0 deletions
@@ -470,6 +470,9 @@ internal fun UnwrappedType.typeDepth() =
internal fun SimpleType.typeDepth(): Int {
if (this is TypeUtils.SpecialType) return 0
if (this is NewCapturedType) {
return constructor.projection.type.unwrap().typeDepth()
}
val maxInArguments = arguments.asSequence().map {
if (it.isStarProjection) 1 else it.type.unwrap().typeDepth()
@@ -0,0 +1,36 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
class Inv<T>(val x: T)
fun case_1(a: Inv<out Inv<Inv<Inv<Inv<Inv<Int?>?>?>?>?>?>?) {
if (a != null) {
val b: Inv<out Inv<out Inv<out Inv<out Inv<Int?>?>?>?>?>? = a.x
}
}
fun case_2(a: Inv<out Inv<Inv<Inv<Inv<Inv<Int?>?>?>?>?>?>?) {
if (a != null) {
val b: Inv<out Inv<out Inv<out Inv<out Inv<Int?>?>?>?>?>? = a.x
if (b != null) {
val c = b.x
if (c != null) {
val d = c.x
if (d != null) {
val e = d.x
if (e != null) {
val f = e.x
if (f != null) {
val g = <!DEBUG_INFO_SMARTCAST!>f<!>.x
if (g != null) {
takeInt(<!DEBUG_INFO_SMARTCAST!>g<!>)
}
}
}
}
}
}
}
}
fun takeInt(i: Int) {}
@@ -0,0 +1,13 @@
package
public fun case_1(/*0*/ a: Inv<out Inv<Inv<Inv<Inv<Inv<kotlin.Int?>?>?>?>?>?>?): kotlin.Unit
public fun case_2(/*0*/ a: Inv<out Inv<Inv<Inv<Inv<Inv<kotlin.Int?>?>?>?>?>?>?): kotlin.Unit
public fun takeInt(/*0*/ i: kotlin.Int): kotlin.Unit
public final class Inv</*0*/ T> {
public constructor Inv</*0*/ T>(/*0*/ x: T)
public final val 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
}
@@ -7943,6 +7943,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
runTest("compiler/testData/diagnostics/tests/generics/argumentsForT.kt");
}
@TestMetadata("capturingOfDeepNestedType.kt")
public void testCapturingOfDeepNestedType() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/capturingOfDeepNestedType.kt");
}
@TestMetadata("commonSupertypeContravariant.kt")
public void testCommonSupertypeContravariant() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.kt");
@@ -7943,6 +7943,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/generics/argumentsForT.kt");
}
@TestMetadata("capturingOfDeepNestedType.kt")
public void testCapturingOfDeepNestedType() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/capturingOfDeepNestedType.kt");
}
@TestMetadata("commonSupertypeContravariant.kt")
public void testCommonSupertypeContravariant() throws Exception {
runTest("compiler/testData/diagnostics/tests/generics/commonSupertypeContravariant.kt");