Change traversal order for finding corresponding supertype from DFS to BFS

In most cases order doesn't matter as in supertype tree built from real code
types with same type constructors should be completely equal.

The only case when order does matter is when we artificially add more specific supertype closer to the root.

For example specific annotation adding non-platform supertype MutableMap<K, V> to ConcurrentHashMap
ConcurrentHashMap<K, V> extends ConcurrentMap<K!, V!> that extends java.util.Map<K!, V!> (mapped to kotlin.MutableMap<K!, V!>)

So we want in that case to use refined (more specific) version when checking subtypes:
ConcurrentHashMap<String, Int> should not be a subtype Map<String!, Int!> (and respectively Map<String?, Int?>)
It should be pure non-platform Map<String, Int> that can be found only with BFS
This commit is contained in:
Denis Zharkov
2015-07-01 14:48:51 +03:00
parent 0a19fb7df2
commit da416f1caf
5 changed files with 97 additions and 11 deletions
@@ -0,0 +1,10 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
interface X<T>
interface A: X<String>
interface B : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>A, X<Int><!>
fun foo(x: B) {
// Checks that when checking subtypes we search closes corresponding constructor (e.g. with BFS)
val y: X<Int> = x
}
@@ -0,0 +1,21 @@
package
internal fun foo(/*0*/ x: B): kotlin.Unit
internal interface A : X<kotlin.String> {
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
}
internal interface B : A, X<kotlin.Int> {
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
internal interface X</*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
}