Use stable order for dependsOn and related diagnostics

This commit is contained in:
Dmitry Savvinov
2019-06-14 16:15:48 +03:00
parent 769ccde43b
commit 68c1a7cedd
4 changed files with 9 additions and 6 deletions
@@ -127,15 +127,15 @@ fun KotlinType.isDefaultBound(): Boolean = KotlinBuiltIns.isDefaultBound(getSupe
fun createProjection(type: KotlinType, projectionKind: Variance, typeParameterDescriptor: TypeParameterDescriptor?): TypeProjection =
TypeProjectionImpl(if (typeParameterDescriptor?.variance == projectionKind) Variance.INVARIANT else projectionKind, type)
fun <T> Collection<T>.closure(f: (T) -> Collection<T>): Collection<T> {
fun <T> Collection<T>.closure(preserveOrder: Boolean = false, f: (T) -> Collection<T>): Collection<T> {
if (size == 0) return this
val result = HashSet(this)
val result = if (preserveOrder) LinkedHashSet(this) else HashSet(this)
var elementsToCheck = result
var oldSize = 0
while (result.size > oldSize) {
oldSize = result.size
val toAdd = hashSetOf<T>()
val toAdd = if (preserveOrder) linkedSetOf() else hashSetOf<T>()
elementsToCheck.forEach { toAdd.addAll(f(it)) }
result.addAll(toAdd)
elementsToCheck = toAdd