Fix Kotlin bytecode toolwindow showing wrong code for suspend functions
Use binding context from the full resolve, because otherwise control-flow analysis is not being run, that is very important for suspend functions (tail-call optimizations) #KT-15827 Fixed
This commit is contained in:
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import java.util.*
|
||||
|
||||
object DebuggerUtils {
|
||||
@@ -101,7 +102,8 @@ object DebuggerUtils {
|
||||
fun analyzeInlinedFunctions(
|
||||
resolutionFacadeForFile: ResolutionFacade,
|
||||
file: KtFile,
|
||||
analyzeOnlyReifiedInlineFunctions: Boolean
|
||||
analyzeOnlyReifiedInlineFunctions: Boolean,
|
||||
bindingContext: BindingContext? = null
|
||||
): Pair<BindingContext, List<KtFile>> {
|
||||
val analyzedElements = HashSet<KtElement>()
|
||||
val context = analyzeElementWithInline(
|
||||
@@ -109,7 +111,8 @@ object DebuggerUtils {
|
||||
file,
|
||||
1,
|
||||
analyzedElements,
|
||||
!analyzeOnlyReifiedInlineFunctions)
|
||||
!analyzeOnlyReifiedInlineFunctions, bindingContext
|
||||
)
|
||||
|
||||
//We processing another files just to annotate anonymous classes within their inline functions
|
||||
//Bytecode not produced for them cause of filtering via generateClassFilter
|
||||
@@ -135,11 +138,14 @@ object DebuggerUtils {
|
||||
element: KtElement,
|
||||
deep: Int,
|
||||
analyzedElements: MutableSet<KtElement>,
|
||||
analyzeInlineFunctions: Boolean): BindingContext {
|
||||
analyzeInlineFunctions: Boolean,
|
||||
fullResolveContext: BindingContext? = null
|
||||
): BindingContext {
|
||||
val project = element.project
|
||||
val inlineFunctions = HashSet<KtNamedFunction>()
|
||||
|
||||
val innerContexts = ArrayList<BindingContext>()
|
||||
innerContexts.addIfNotNull(fullResolveContext)
|
||||
|
||||
element.accept(object : KtTreeVisitorVoid() {
|
||||
override fun visitExpression(expression: KtExpression) {
|
||||
|
||||
@@ -292,8 +292,11 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
|
||||
) {
|
||||
ResolutionFacade resolutionFacade = ResolutionUtils.getResolutionFacade(ktFile);
|
||||
|
||||
BindingContext bindingContextForFile = resolutionFacade.analyzeFullyAndGetResult(Collections.singletonList(ktFile)).getBindingContext();
|
||||
|
||||
kotlin.Pair<BindingContext, List<KtFile>> result = DebuggerUtils.INSTANCE.analyzeInlinedFunctions(
|
||||
resolutionFacade, ktFile, configuration.getBoolean(CommonConfigurationKeys.DISABLE_INLINE)
|
||||
resolutionFacade, ktFile, configuration.getBoolean(CommonConfigurationKeys.DISABLE_INLINE),
|
||||
bindingContextForFile
|
||||
);
|
||||
|
||||
BindingContext bindingContext = result.getFirst();
|
||||
|
||||
Reference in New Issue
Block a user