[FIR] Add DeclaredUpperBoundConstraintPosition to Fir

This commit is contained in:
Dmitriy Novozhilov
2019-07-24 16:11:38 +03:00
committed by Mikhail Glukhikh
parent d3670d4f5f
commit 7245475196
3 changed files with 10 additions and 8 deletions
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.symbols.invoke
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.impl.FirTypePlaceholderProjection
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation
import org.jetbrains.kotlin.resolve.calls.inference.model.FirDeclaredUpperBoundConstraintPosition
import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition
@@ -102,7 +103,7 @@ fun createToFreshVariableSubstitutorAndAddInitialConstraints(
upperBound: ConeKotlinType//,
//position: DeclaredUpperBoundConstraintPosition
) {
csBuilder.addSubtypeConstraint(defaultType, toFreshVariables.substituteOrSelf(upperBound), SimpleConstraintSystemConstraintPosition)
csBuilder.addSubtypeConstraint(defaultType, toFreshVariables.substituteOrSelf(upperBound), FirDeclaredUpperBoundConstraintPosition())
}
for (index in typeParameters.indices) {
@@ -13,10 +13,7 @@ import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
import org.jetbrains.kotlin.resolve.calls.components.TypeArgumentsToParametersMapper.TypeArgumentsMapping.NoExplicitArguments
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation
import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.model.DeclaredUpperBoundConstraintPosition
import org.jetbrains.kotlin.resolve.calls.inference.model.ExplicitTypeParameterConstraintPosition
import org.jetbrains.kotlin.resolve.calls.inference.model.KnownTypeParameterConstraintPosition
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableFromCallableDescriptor
import org.jetbrains.kotlin.resolve.calls.inference.model.*
import org.jetbrains.kotlin.resolve.calls.inference.substitute
import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.resolve.calls.smartcasts.getReceiverValueWithSmartCast
@@ -197,7 +194,7 @@ internal object CreateFreshVariablesSubstitutor : ResolutionPart() {
for (index in typeParameters.indices) {
val typeParameter = typeParameters[index]
val freshVariable = freshTypeVariables[index]
val position = DeclaredUpperBoundConstraintPosition(typeParameter)
val position = DeclaredUpperBoundConstraintPositionImpl(typeParameter)
for (upperBound in typeParameter.upperBounds) {
freshVariable.addSubtypeConstraint(upperBound, position)
@@ -218,7 +215,7 @@ internal object CreateFreshVariablesSubstitutor : ResolutionPart() {
// there can be null in case we already captured type parameter in outer class (in case of inner classes)
// see test innerClassTypeAliasConstructor.kt
val originalTypeParameter = originalTypeParameters.getOrNull(originalIndex) ?: continue
val position = DeclaredUpperBoundConstraintPosition(originalTypeParameter)
val position = DeclaredUpperBoundConstraintPositionImpl(originalTypeParameter)
for (upperBound in originalTypeParameter.upperBounds) {
freshVariable.addSubtypeConstraint(upperBound, position)
}
@@ -37,10 +37,14 @@ class ExpectedTypeConstraintPosition(val topLevelCall: KotlinCall) : ConstraintP
override fun toString() = "ExpectedType for call $topLevelCall"
}
class DeclaredUpperBoundConstraintPosition(val typeParameterDescriptor: TypeParameterDescriptor) : ConstraintPosition() {
sealed class DeclaredUpperBoundConstraintPosition : ConstraintPosition()
class DeclaredUpperBoundConstraintPositionImpl(val typeParameterDescriptor: TypeParameterDescriptor) : DeclaredUpperBoundConstraintPosition() {
override fun toString() = "DeclaredUpperBound ${typeParameterDescriptor.name} from ${typeParameterDescriptor.containingDeclaration}"
}
class FirDeclaredUpperBoundConstraintPosition : DeclaredUpperBoundConstraintPosition()
class ArgumentConstraintPosition(val argument: KotlinCallArgument) : ConstraintPosition() {
override fun toString() = "Argument $argument"
}