[NI] Make subtyping algorithm more robust to error types

During subtyping/incorporation we transform types (e.g. changing nullability,
 form of the type) and, basically, we're doing this to some FIXPOINT.
 It's important that we use `KotlinType.hashCode()` to compare types, but
 for error types hashCode is a hashCode of its supertype and, for example,
 `makeNullableAsSpecified` method recreate type every time. So, we continue
 to generate new constraints and we'll never stop incorporation algorithm
This commit is contained in:
Mikhail Zarechenskiy
2018-06-07 11:48:16 +03:00
parent 1ee37b1772
commit 9891f562cc
15 changed files with 94 additions and 20 deletions
@@ -0,0 +1,26 @@
// !LANGUAGE: +NewInference
// FILE: Sam.java
public interface Sam<K> {
Sam.Result<K> compute();
public static class Result<V> {
public static <V> Sam.Result<V> create(V value) {}
}
}
// FILE: Foo.java
public class Foo {
public static <T> void foo(Sam<T> var1) {
}
}
// FILE: test.kt
fun test(e: <!UNRESOLVED_REFERENCE!>ErrorType<!>) {
Foo.foo {
Sam.Result.create(<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>e<!>)
}
}
@@ -0,0 +1,30 @@
package
public fun test(/*0*/ e: [ERROR : ErrorType]): kotlin.Unit
public open class Foo {
public constructor Foo()
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
// Static members
public open fun </*0*/ T : kotlin.Any!> foo(/*0*/ var1: Sam<T!>!): kotlin.Unit
}
public interface Sam</*0*/ K : kotlin.Any!> {
public abstract fun compute(): Sam.Result<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 Result</*0*/ V : kotlin.Any!> {
public constructor Result</*0*/ V : kotlin.Any!>()
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
// Static members
public open fun </*0*/ V : kotlin.Any!> create(/*0*/ value: V!): Sam.Result<V!>!
}
}
@@ -57,7 +57,7 @@ fun test3(z: Z) {
//'in' operation
fun test4(collection: Collection<A<*>>) {
id(<!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>newA<!>() in collection)
id(newA<Int>() in collection)
<!NI;UNREACHABLE_CODE!>id(newA<Int>() in collection)<!>
}
//boolean operations
@@ -3,7 +3,7 @@ fun foo() {
fun bar1() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!><!NI;DEBUG_INFO_MISSING_UNRESOLVED!>bar1<!>()<!>
fun bar2() = 1 <!NI;OVERLOAD_RESOLUTION_AMBIGUITY!>+<!> <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!><!NI;DEBUG_INFO_MISSING_UNRESOLVED!>bar2<!>()<!>
fun bar3() = id(<!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!><!NI;DEBUG_INFO_MISSING_UNRESOLVED!>bar3<!>()<!>)
fun <!NI;IMPLICIT_NOTHING_RETURN_TYPE!>bar3<!>() = id(<!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!><!NI;DEBUG_INFO_MISSING_UNRESOLVED!>bar3<!>()<!>)
}
fun <T> id(x: T) = x