Skip to content

Commit 502e844

Browse files
bnormSpace Team
authored andcommitted
Explain: fix for destructuring declarations
#KT-85103 fixed
1 parent 0c26485 commit 502e844

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

plugins/scripting/scripting-compiler/src/org/jetbrains/kotlin/scripting/compiler/plugin/extensions/ScriptingProcessSourcesBeforeCompilingExtension.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,17 @@ class KotlinScriptExpressionExplainTransformer(
177177
statement
178178
}
179179
}
180+
is IrComposite -> {
181+
if (statement.origin == IrStatementOrigin.DESTRUCTURING_DECLARATION) {
182+
// Only the first statement of a destructing declaration should be transformed. Otherwise, the backend got confused.
183+
// The first statement is the assignment to the destructuring var anyway, so we don't lose information here.
184+
statement.statements[0] = explainStatement(statement.statements[0], builder, explanationsProp, declaration, "")
185+
statement
186+
} else {
187+
statement.statements.transformInPlace { explainStatement(it, builder, explanationsProp, declaration, "") }
188+
statement
189+
}
190+
}
180191
is IrExpression -> {
181192
if (statement is IrTypeOperatorCall && statement.operator == IrTypeOperator.IMPLICIT_COERCION_TO_UNIT) {
182193
statement.argument = explainWithFallBack(statement.argument, declaration, statementName, builder, explanationsProp)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<destruct>(17, 25) = (1, 2)
2+
(26, 29) = 1
3+
(30, 33) = 2
4+
<destruct>(49, 57) = (3, 4)
5+
$$result(58, 61) = 4

plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/plugin/ScriptingWithExplanationCompilerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class ScriptingWithExplanationCompilerTest {
126126

127127
@Test // KT-85103
128128
fun testScriptExplainDestructuringDeclarations() {
129-
runScriptAndValidateExplain("$TEST_DATA_DIR/destructuringDecls.kts", expectedExitCode = ExitCode.COMPILATION_ERROR)
129+
runScriptAndValidateExplain("$TEST_DATA_DIR/destructuringDecls.kts", expectedExitCode = ExitCode.OK)
130130
}
131131

132132
@Test // KT-85105

0 commit comments

Comments
 (0)