[NI] Fix inference of lambda with receiver when wrapped...

in when/if or another lambda.
#KT-37419 fixed
This commit is contained in:
Ilya Chernikov
2020-04-12 18:20:31 +02:00
parent 6494a2d902
commit acc5633811
10 changed files with 228 additions and 23 deletions
@@ -263,9 +263,12 @@ class KotlinConstraintSystemCompleter(
c.notFixedTypeVariables.getValue(variable),
TypeVariableDirectionCalculator.ResolveDirection.TO_SUPERTYPE
) as KotlinType
val isExtensionWithoutParameters =
functionalType.isExtensionFunctionType && functionalType.arguments.size == 2 && parameterTypes?.isEmpty() == true
if (parameterTypes?.all { type -> type != null } == true && !isExtensionWithoutParameters) return this
val isExtensionFunction = functionalType.isExtensionFunctionType
val isExtensionFunctionWithReceiverAsDeclaredParameter =
isExtensionFunction && functionalType.arguments.size - 1 == parameterTypes?.count { it != null }
if (parameterTypes?.all { it != null } == true && (!isExtensionFunction || isExtensionFunctionWithReceiverAsDeclaredParameter)) return this
if (!functionalType.isSuitable()) return this
val returnVariable = typeVariableCreator()
csBuilder.registerVariable(returnVariable)