From badbf777df97c8d6acdf79c3414b9fec6e97a40f Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Wed, 7 Jun 2017 13:52:31 +0300 Subject: [PATCH] [NI] Use data flow info from arguments in parenthesis to resolve lambda Fixes 'javaObjectType' and 'javaPrimitiveType' --- .../calls/tower/KotlinResolutionCallbacksImpl.kt | 10 ++++++---- .../resolve/calls/components/ExternalComponents.kt | 5 ++--- .../resolve/calls/components/KotlinCallCompleter.kt | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt index e06c3a67597..a7fda827304 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt @@ -67,7 +67,7 @@ class KotlinResolutionCallbacksImpl( } override fun analyzeAndGetLambdaResultArguments( - topLevelCall: KotlinCall, + outerCall: KotlinCall, lambdaArgument: LambdaKotlinCallArgument, isSuspend: Boolean, receiverType: UnwrappedType?, @@ -100,9 +100,11 @@ class KotlinResolutionCallbacksImpl( val approximatesExpectedType = typeApproximator.approximateToSubType(expectedType, TypeApproximatorConfiguration.LocalDeclaration) ?: expectedType - val actualContext = outerCallContext.replaceBindingTrace(trace). - replaceContextDependency(lambdaInfo.contextDependency).replaceExpectedType(approximatesExpectedType) - + val actualContext = outerCallContext + .replaceBindingTrace(trace) + .replaceContextDependency(lambdaInfo.contextDependency) + .replaceExpectedType(approximatesExpectedType) + .replaceDataFlowInfo(outerCall.psiKotlinCall.resultDataFlowInfo) val functionTypeInfo = expressionTypingServices.getTypeInfo(expression, actualContext) trace.record(BindingContext.NEW_INFERENCE_LAMBDA_INFO, ktFunction, LambdaInfo.STUB_EMPTY) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt index 516acfe2d61..0e75637a7fe 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package org.jetbrains.kotlin.resolve.calls.components import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.resolve.calls.model.* -import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.UnwrappedType interface IsDescriptorFromSourcePredicate: (CallableDescriptor) -> Boolean @@ -26,7 +25,7 @@ interface IsDescriptorFromSourcePredicate: (CallableDescriptor) -> Boolean // This components hold state (trace). Work with this carefully. interface KotlinResolutionCallbacks { fun analyzeAndGetLambdaResultArguments( - topLevelCall: KotlinCall, + outerCall: KotlinCall, lambdaArgument: LambdaKotlinCallArgument, isSuspend: Boolean, receiverType: UnwrappedType?, diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt index b915cc266f7..38bb1c30bfd 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt @@ -260,7 +260,7 @@ class KotlinCallCompleter( val parameters = lambda.parameters.map(::substitute) val expectedType = lambda.returnType.takeIf { c.canBeProper(it) }?.let(::substitute) lambda.analyzed = true - lambda.resultArguments = resolutionCallbacks.analyzeAndGetLambdaResultArguments(topLevelCall, lambda.argument, lambda.isSuspend, receiver, parameters, expectedType) + lambda.resultArguments = resolutionCallbacks.analyzeAndGetLambdaResultArguments(lambda.outerCall, lambda.argument, lambda.isSuspend, receiver, parameters, expectedType) for (innerCall in lambda.resultArguments) { // todo strange code -- why top-level kotlinCall? may be it isn't right outer call