Fix inference for lambdas with with extension function expected type

^KT-49832 Fixed
^KT-49836 Fixed
This commit is contained in:
Denis.Zharkov
2021-11-23 10:25:07 +03:00
committed by teamcityserver
parent 3fb17cfa9a
commit 0d9ad62d4a
16 changed files with 320 additions and 16 deletions
@@ -91,6 +91,11 @@ object ConeConstraintSystemUtilContext : ConstraintSystemUtilContext {
return this is LambdaWithTypeVariableAsExpectedTypeAtom && !this.atom.anonymousFunction.isLambda && this.atom.anonymousFunction.receiverTypeRef?.coneType != null
}
override fun PostponedAtomWithRevisableExpectedType.isLambda(): Boolean {
require(this is PostponedResolvedAtom)
return this is LambdaWithTypeVariableAsExpectedTypeAtom && this.atom.anonymousFunction.isLambda
}
override fun createTypeVariableForLambdaReturnType(): TypeVariableMarker {
return ConeTypeVariableForPostponedAtom(PostponedArgumentInputTypesResolver.TYPE_VARIABLE_NAME_FOR_LAMBDA_RETURN_TYPE)
}
@@ -117,4 +122,7 @@ object ConeConstraintSystemUtilContext : ConstraintSystemUtilContext {
override fun createTypeVariableForCallableReferenceReturnType(): TypeVariableMarker {
return ConeTypeVariableForPostponedAtom(PostponedArgumentInputTypesResolver.TYPE_VARIABLE_NAME_FOR_LAMBDA_RETURN_TYPE)
}
override val isForcedConsiderExtensionReceiverFromConstrainsInLambda: Boolean
get() = true
}
@@ -30,7 +30,9 @@ class InferenceComponents(val session: FirSession) : FirSessionComponent {
val resultTypeResolver = ResultTypeResolver(approximator, trivialConstraintTypeInferenceOracle, session.languageVersionSettings)
val variableFixationFinder = VariableFixationFinder(trivialConstraintTypeInferenceOracle, session.languageVersionSettings)
val postponedArgumentInputTypesResolver =
PostponedArgumentInputTypesResolver(resultTypeResolver, variableFixationFinder, ConeConstraintSystemUtilContext)
PostponedArgumentInputTypesResolver(
resultTypeResolver, variableFixationFinder, ConeConstraintSystemUtilContext, session.languageVersionSettings
)
val constraintSystemFactory = ConstraintSystemFactory()