Skip to content

Commit 0c26485

Browse files
bnormSpace Team
authored andcommitted
Explain: fix for object literals
#KT-85105 fixed
1 parent 68a9e3f commit 0c26485

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,13 @@ class KotlinScriptExpressionExplainTransformer(
169169
explainWithFallBack(statement, declaration, statementName, builder, explanationsProp)
170170
}
171171
is IrBlock -> {
172-
statement.statements.transformInPlace { explainStatement(it, builder, explanationsProp, declaration, "") }
173-
statement
172+
if (statement.origin == IrStatementOrigin.OBJECT_LITERAL) {
173+
// Object literals need to be explained as a whole.
174+
explainWithFallBack(statement, declaration, statementName, builder, explanationsProp)
175+
} else {
176+
statement.statements.transformInPlace { explainStatement(it, builder, explanationsProp, declaration, "") }
177+
statement
178+
}
174179
}
175180
is IrExpression -> {
176181
if (statement is IrTypeOperatorCall && statement.operator == IrTypeOperator.IMPLICIT_COERCION_TO_UNIT) {
@@ -229,4 +234,4 @@ class ScriptingProcessSourcesBeforeCompilingExtension(val project: Project) : Pr
229234
}
230235
}
231236
}
232-
}
237+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(108, 117) = MyClass()
2+
(118, 123) = 1
3+
i(169, 300) = `<no name provided>`()
4+
$$result(301, 302) = `<no name provided>`()
5+
$$result(303, 308) = 1

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
@@ -131,7 +131,7 @@ class ScriptingWithExplanationCompilerTest {
131131

132132
@Test // KT-85105
133133
fun testScriptExplainWithObjectLiteral() {
134-
runScriptAndValidateExplain("$TEST_DATA_DIR/objectLiteral.kts", expectedExitCode = ExitCode.COMPILATION_ERROR)
134+
runScriptAndValidateExplain("$TEST_DATA_DIR/objectLiteral.kts", expectedExitCode = ExitCode.OK)
135135
}
136136
}
137137

0 commit comments

Comments
 (0)