From 22f18149110775a69ea52777f73e2d2b8bc5ca28 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Sun, 7 Mar 2021 18:01:13 +0100 Subject: [PATCH] Fix CFA for destructuring declarations in scripts in particular without the fix, the CFA skipped marking of the used result values in lambdas and they were coerced to unit in IR --- .../jetbrains/kotlin/cfg/ControlFlowProcessor.kt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/compiler/frontend/cfg/src/org/jetbrains/kotlin/cfg/ControlFlowProcessor.kt b/compiler/frontend/cfg/src/org/jetbrains/kotlin/cfg/ControlFlowProcessor.kt index bdeaee6c49c..f1e784c78c1 100644 --- a/compiler/frontend/cfg/src/org/jetbrains/kotlin/cfg/ControlFlowProcessor.kt +++ b/compiler/frontend/cfg/src/org/jetbrains/kotlin/cfg/ControlFlowProcessor.kt @@ -1329,7 +1329,7 @@ class ControlFlowProcessor( override fun visitObjectDeclaration(objectDeclaration: KtObjectDeclaration) { generateHeaderDelegationSpecifiers(objectDeclaration) - generateInitializersForScriptClassOrObject(objectDeclaration) + generateInitializersForClassOrObject(objectDeclaration) generateDeclarationForLocalClassOrObjectIfNeeded(objectDeclaration) } @@ -1363,7 +1363,7 @@ class ControlFlowProcessor( } } - private fun generateInitializersForScriptClassOrObject(classOrObject: KtDeclarationContainer) { + private fun generateInitializersForClassOrObject(classOrObject: KtDeclarationContainer) { for (declaration in classOrObject.declarations) { if (declaration is KtProperty || declaration is KtAnonymousInitializer) { generateInstructions(declaration) @@ -1389,7 +1389,7 @@ class ControlFlowProcessor( // delegation specifiers of primary constructor, anonymous class and property initializers generateHeaderDelegationSpecifiers(klass) - generateInitializersForScriptClassOrObject(klass) + generateInitializersForClassOrObject(klass) } generateDeclarationForLocalClassOrObjectIfNeeded(klass) @@ -1409,7 +1409,11 @@ class ControlFlowProcessor( } override fun visitScript(script: KtScript) { - generateInitializersForScriptClassOrObject(script) + for (declaration in script.declarations) { + if (declaration is KtProperty || declaration is KtAnonymousInitializer || declaration is KtDestructuringDeclaration) { + generateInstructions(declaration) + } + } } private fun generateDeclarationForLocalClassOrObjectIfNeeded(classOrObject: KtClassOrObject) { @@ -1440,7 +1444,7 @@ class ControlFlowProcessor( generateCallOrMarkUnresolved(constructor.getDelegationCall()) if (!constructor.getDelegationCall().isCallToThis) { - generateInitializersForScriptClassOrObject(classOrObject) + generateInitializersForClassOrObject(classOrObject) } generateInstructions(constructor.bodyExpression) @@ -1577,7 +1581,7 @@ class ControlFlowProcessor( when (kind) { ExplicitReceiverKind.DISPATCH_RECEIVER -> explicitReceiver = resolvedCall.dispatchReceiver ExplicitReceiverKind.EXTENSION_RECEIVER, ExplicitReceiverKind.BOTH_RECEIVERS -> explicitReceiver = - resolvedCall.extensionReceiver + resolvedCall.extensionReceiver ExplicitReceiverKind.NO_EXPLICIT_RECEIVER -> { } }