Remove assertion about dispatch receiver in scripts

#KT-42530 fixed
This commit is contained in:
Ilya Chernikov
2020-12-17 19:27:38 +01:00
parent 0671fd9aaa
commit 65cf941b9b
3 changed files with 17 additions and 1 deletions
@@ -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());
@@ -0,0 +1,5 @@
fun Int.isOdd() = (this % 2) == 1
val list: List<Pair<Int, String>> = listOf(1 to "a", 2 to "b")
val (odds, evens) = list.partition { (i, _) -> i.isOdd() }
odds
@@ -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,