Fix problem with missing handleResult call

At first we try to resolve 'handleResult' just as last expression
in a lambda is first argument, then if results are unsuccessful
try resolve 'handleResult' with fake Unit expression

 #KT-12969 Fixed
This commit is contained in:
Denis Zharkov
2016-07-04 18:07:16 +03:00
parent 888db4b3b5
commit a420fda825
3 changed files with 57 additions and 10 deletions
@@ -72,21 +72,34 @@ fun FakeCallResolver.resolveCoroutineHandleResultCallIfNeeded(
// should be Continuation<Nothing>
functionDescriptor.builtIns.nothingType)
fun tryToResolveCall(firstArgument: KtExpression): Boolean {
val resolutionResults = resolveFakeCall(
context.replaceBindingTrace(temporaryBindingTrace), functionDescriptor.extensionReceiverParameter!!.value,
OperatorNameConventions.COROUTINE_HANDLE_RESULT, callElement, callElement, FakeCallKind.OTHER,
listOf(firstArgument, continuation))
if (resolutionResults.isSuccess && resolutionResults.resultingDescriptor.isOperator) {
context.trace.record(BindingContext.RETURN_HANDLE_RESULT_RESOLVED_CALL, callElement, resolutionResults.resultingCall)
return true
}
return false
}
val unitExpression = ExpressionTypingUtils.createFakeExpressionOfType(
callElement.project, temporaryBindingTrace, "unit", functionDescriptor.builtIns.unitType)
val firstArgument =
if (expressionToReturn == null || info != null && info.type != null && KotlinBuiltIns.isUnit(info.type))
ExpressionTypingUtils.createFakeExpressionOfType(
callElement.project, temporaryBindingTrace, "unit", functionDescriptor.builtIns.unitType)
else expressionToReturn
unitExpression
else
expressionToReturn
val resolutionResults = resolveFakeCall(
context.replaceBindingTrace(temporaryBindingTrace), functionDescriptor.extensionReceiverParameter!!.value,
OperatorNameConventions.COROUTINE_HANDLE_RESULT, callElement, callElement, FakeCallKind.OTHER,
listOf(firstArgument, continuation))
if (resolutionResults.isSuccess && resolutionResults.resultingDescriptor.isOperator) {
context.trace.record(BindingContext.RETURN_HANDLE_RESULT_RESOLVED_CALL, callElement, resolutionResults.resultingCall)
if (!tryToResolveCall(firstArgument) && firstArgument === expressionToReturn) {
tryToResolveCall(unitExpression)
}
}
fun KotlinType.isValidContinuation() =
(constructor.declarationDescriptor as? ClassDescriptor)?.fqNameUnsafe == DescriptorUtils.CONTINUATION_INTERFACE_FQ_NAME.toUnsafe()