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 {