From 295f7d7500ccece1c450ad38653874fb778cd71d Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Tue, 12 May 2020 17:41:34 +0300 Subject: [PATCH] FIR: Do not add trivial constraints --- ...CreateFreshTypeVariableSubstitutorStage.kt | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CreateFreshTypeVariableSubstitutorStage.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CreateFreshTypeVariableSubstitutorStage.kt index ee1cdc30d8d..404e6d14482 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CreateFreshTypeVariableSubstitutorStage.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CreateFreshTypeVariableSubstitutorStage.kt @@ -5,14 +5,14 @@ package org.jetbrains.kotlin.fir.resolve.calls -import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRefsOwner -import org.jetbrains.kotlin.fir.declarations.FirTypeParameter +import org.jetbrains.kotlin.fir.FirSession 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.resolve.inference.TypeParameterBasedTypeVariable import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor 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.types.* import org.jetbrains.kotlin.fir.types.impl.FirTypePlaceholderProjection @@ -30,7 +30,8 @@ internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() { return } 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.freshVariables = freshVariables @@ -113,7 +114,8 @@ internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() { fun createToFreshVariableSubstitutorAndAddInitialConstraints( declaration: FirTypeParameterRefsOwner, candidate: Candidate, - csBuilder: ConstraintSystemOperation + csBuilder: ConstraintSystemOperation, + session: FirSession ): Pair> { val typeParameters = declaration.typeParameters @@ -130,7 +132,17 @@ fun createToFreshVariableSubstitutorAndAddInitialConstraints( upperBound: ConeKotlinType//, //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) {