Reuse built functional types for postponed arguments by expected types and paths from a top level type variable

^KT-42221 Fixed
This commit is contained in:
Victor Petukhov
2020-10-14 18:02:17 +03:00
parent ee5edf4caa
commit c6da2a1138
18 changed files with 538 additions and 57 deletions
@@ -7,6 +7,8 @@ package org.jetbrains.kotlin.types.model
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
import org.jetbrains.kotlin.types.Variance
import java.util.*
import kotlin.collections.ArrayList
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
@@ -207,6 +209,25 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
fun getFunctionTypeConstructor(parametersNumber: Int, isSuspend: Boolean): TypeConstructorMarker
fun getKFunctionTypeConstructor(parametersNumber: Int, isSuspend: Boolean): TypeConstructorMarker
private fun KotlinTypeMarker.extractTypeVariables(to: MutableSet<TypeVariableTypeConstructorMarker>) {
for (i in 0 until argumentsCount()) {
val argument = getArgument(i)
if (argument.isStarProjection()) continue
val argumentType = argument.getType()
val argumentTypeConstructor = argumentType.typeConstructor()
if (argumentTypeConstructor is TypeVariableTypeConstructorMarker) {
to.add(argumentTypeConstructor)
} else if (argumentType.argumentsCount() != 0) {
argumentType.extractTypeVariables(to)
}
}
}
@OptIn(ExperimentalStdlibApi::class)
fun KotlinTypeMarker.extractTypeVariables() = buildSet { extractTypeVariables(this) }
}