FIR: Do not add trivial constraints
This commit is contained in:
+18
-6
@@ -5,14 +5,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.resolve.calls
|
package org.jetbrains.kotlin.fir.resolve.calls
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRefsOwner
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRef
|
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRef
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParametersOwner
|
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRefsOwner
|
||||||
import org.jetbrains.kotlin.fir.renderWithType
|
import org.jetbrains.kotlin.fir.renderWithType
|
||||||
import org.jetbrains.kotlin.fir.resolve.inference.TypeParameterBasedTypeVariable
|
import org.jetbrains.kotlin.fir.resolve.inference.TypeParameterBasedTypeVariable
|
||||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||||
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
|
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.types.impl.FirTypePlaceholderProjection
|
import org.jetbrains.kotlin.fir.types.impl.FirTypePlaceholderProjection
|
||||||
@@ -30,7 +30,8 @@ internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
val csBuilder = candidate.system.getBuilder()
|
val csBuilder = candidate.system.getBuilder()
|
||||||
val (substitutor, freshVariables) = createToFreshVariableSubstitutorAndAddInitialConstraints(declaration, candidate, csBuilder)
|
val (substitutor, freshVariables) =
|
||||||
|
createToFreshVariableSubstitutorAndAddInitialConstraints(declaration, candidate, csBuilder, callInfo.session)
|
||||||
candidate.substitutor = substitutor
|
candidate.substitutor = substitutor
|
||||||
candidate.freshVariables = freshVariables
|
candidate.freshVariables = freshVariables
|
||||||
|
|
||||||
@@ -113,7 +114,8 @@ internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() {
|
|||||||
fun createToFreshVariableSubstitutorAndAddInitialConstraints(
|
fun createToFreshVariableSubstitutorAndAddInitialConstraints(
|
||||||
declaration: FirTypeParameterRefsOwner,
|
declaration: FirTypeParameterRefsOwner,
|
||||||
candidate: Candidate,
|
candidate: Candidate,
|
||||||
csBuilder: ConstraintSystemOperation
|
csBuilder: ConstraintSystemOperation,
|
||||||
|
session: FirSession
|
||||||
): Pair<ConeSubstitutor, List<ConeTypeVariable>> {
|
): Pair<ConeSubstitutor, List<ConeTypeVariable>> {
|
||||||
|
|
||||||
val typeParameters = declaration.typeParameters
|
val typeParameters = declaration.typeParameters
|
||||||
@@ -130,7 +132,17 @@ fun createToFreshVariableSubstitutorAndAddInitialConstraints(
|
|||||||
upperBound: ConeKotlinType//,
|
upperBound: ConeKotlinType//,
|
||||||
//position: DeclaredUpperBoundConstraintPosition
|
//position: DeclaredUpperBoundConstraintPosition
|
||||||
) {
|
) {
|
||||||
csBuilder.addSubtypeConstraint(defaultType, toFreshVariables.substituteOrSelf(upperBound), FirDeclaredUpperBoundConstraintPosition())
|
if ((upperBound.lowerBoundIfFlexible() as? ConeClassLikeType)?.lookupTag?.classId == StandardClassIds.Any &&
|
||||||
|
upperBound.upperBoundIfFlexible().isMarkedNullable
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
csBuilder.addSubtypeConstraint(
|
||||||
|
defaultType,
|
||||||
|
toFreshVariables.substituteOrSelf(upperBound),
|
||||||
|
FirDeclaredUpperBoundConstraintPosition()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (index in typeParameters.indices) {
|
for (index in typeParameters.indices) {
|
||||||
|
|||||||
Reference in New Issue
Block a user