From 5ec8d4920fd2c34dcdc2c0c0bb0d0d32b8a3445d Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Tue, 27 Jun 2017 02:39:53 +0300 Subject: [PATCH] [NI] Translate new resolved call to old one to avoid CCE --- .../coroutines/coroutineCodegenUtil.kt | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutineCodegenUtil.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutineCodegenUtil.kt index e1aa95fb744..b76503b2ef4 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutineCodegenUtil.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/coroutineCodegenUtil.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. @@ -37,6 +37,7 @@ import org.jetbrains.kotlin.resolve.* import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy +import org.jetbrains.kotlin.resolve.calls.tower.NewResolvedCallImpl import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.resolve.jvm.AsmTypes @@ -103,7 +104,7 @@ fun ResolvedCall<*>.replaceSuspensionFunctionWithRealDescriptor( return replacedFunctionCall.copy( VariableAsFunctionResolvedCallImpl( replacedFunctionCall.resolvedCall as MutableResolvedCall, - variableCall as MutableResolvedCall + variableCall.asMutableResolvedCall(bindingContext) ) ) } @@ -148,6 +149,24 @@ fun ResolvedCall<*>.replaceSuspensionFunctionWithRealDescriptor( return ResolvedCallWithRealDescriptor(newCall, thisExpression) } +private fun ResolvedCall.asMutableResolvedCall(bindingContext: BindingContext): MutableResolvedCall { + return when (this) { + is ResolvedCallImpl<*> -> this as MutableResolvedCall + is NewResolvedCallImpl<*> -> (this as NewResolvedCallImpl).asDummyOldResolvedCall(bindingContext) + else -> throw IllegalStateException("No mutable resolved call for $this") + } +} + +private fun NewResolvedCallImpl.asDummyOldResolvedCall(bindingContext: BindingContext): ResolvedCallImpl { + return ResolvedCallImpl( + call, + candidateDescriptor, + dispatchReceiver, extensionReceiver, explicitReceiverKind, + null, DelegatingBindingTrace(bindingContext, "Trace for old call"), + TracingStrategy.EMPTY, MutableDataFlowInfoForArguments.WithoutArgumentsCheck(DataFlowInfo.EMPTY) + ) +} + fun ResolvedCall<*>.isSuspendNoInlineCall() = resultingDescriptor.safeAs() ?.let {