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,