From 65cf941b9beb62972cd12203ecd367d6bc21e30c Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Thu, 17 Dec 2020 19:27:38 +0100 Subject: [PATCH] Remove assertion about dispatch receiver in scripts #KT-42530 fixed --- .../jetbrains/kotlin/resolve/DescriptorResolver.java | 3 ++- .../scripting-compiler/testData/compiler/kt42530.kts | 5 +++++ .../kotlin/scripting/compiler/test/ScriptTest.kt | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 plugins/scripting/scripting-compiler/testData/compiler/kt42530.kts diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java index 2714eeef1ff..ac2ed637f87 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java @@ -328,7 +328,8 @@ public class DescriptorResolver { } destructuringVariables = () -> { - assert owner.getDispatchReceiverParameter() == null + ReceiverParameterDescriptor dispatchReceiver = owner.getDispatchReceiverParameter(); + assert dispatchReceiver == null || dispatchReceiver.getContainingDeclaration() instanceof ScriptDescriptor : "Destructuring declarations are only be parsed for lambdas, and they must not have a dispatch receiver"; LexicalScope scopeForDestructuring = ScopeUtilsKt.createScopeForDestructuring(scope, owner.getExtensionReceiverParameter()); diff --git a/plugins/scripting/scripting-compiler/testData/compiler/kt42530.kts b/plugins/scripting/scripting-compiler/testData/compiler/kt42530.kts new file mode 100644 index 00000000000..dcde2199a13 --- /dev/null +++ b/plugins/scripting/scripting-compiler/testData/compiler/kt42530.kts @@ -0,0 +1,5 @@ + +fun Int.isOdd() = (this % 2) == 1 +val list: List> = listOf(1 to "a", 2 to "b") +val (odds, evens) = list.partition { (i, _) -> i.isOdd() } +odds diff --git a/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/test/ScriptTest.kt b/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/test/ScriptTest.kt index 174579f0f3e..73e4f3c8ec4 100644 --- a/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/test/ScriptTest.kt +++ b/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/test/ScriptTest.kt @@ -76,6 +76,16 @@ class ScriptTest : TestCase() { }) } + fun testKt42530() { + val aClass = compileScript("kt42530.kts", StandardScriptDefinition) + Assert.assertNotNull(aClass) + val out = captureOut { + val anObj = tryConstructClassFromStringArgs(aClass!!, emptyList()) + Assert.assertNotNull(anObj) + } + assertEqualsTrimmed("[(1, a)]", out) + } + private fun compileScript( scriptPath: String, scriptDefinition: KotlinScriptDefinition,