From 0d7a5c6b1b84a04df630f846b500e8063e8c518f Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Fri, 7 Jul 2023 12:48:05 +0200 Subject: [PATCH] Scripting: fix string script source location fixes proper script definition discovery for expressions and other scripts created from a string. --- .../script/experimental/host/scriptHostUtil.kt | 2 +- .../plugin/ScriptingWithCliCompilerTest.kt | 14 +++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/libraries/scripting/common/src/kotlin/script/experimental/host/scriptHostUtil.kt b/libraries/scripting/common/src/kotlin/script/experimental/host/scriptHostUtil.kt index f2b15ca4bb9..75e10dfcf2a 100644 --- a/libraries/scripting/common/src/kotlin/script/experimental/host/scriptHostUtil.kt +++ b/libraries/scripting/common/src/kotlin/script/experimental/host/scriptHostUtil.kt @@ -108,7 +108,7 @@ open class StringScriptSource(val source: String, override val name: String? = n override val text: String get() = source - override val locationId: String? = null + override val locationId: String? get() = name override fun equals(other: Any?): Boolean = this === other || (other as? StringScriptSource)?.let { text == it.text && name == it.name && locationId == it.locationId } == true diff --git a/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/plugin/ScriptingWithCliCompilerTest.kt b/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/plugin/ScriptingWithCliCompilerTest.kt index 2560c57fb61..9f5ae9a4d53 100644 --- a/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/plugin/ScriptingWithCliCompilerTest.kt +++ b/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/plugin/ScriptingWithCliCompilerTest.kt @@ -71,28 +71,20 @@ class ScriptingWithCliCompilerTest { runWithK2JVMCompiler( arrayOf( "-cp", getMainKtsClassPath().joinToString(File.pathSeparator), - "-expression", - "\\@file:CompilerOptions(\"-Xunknown1\")" + "-expression=@file:CompilerOptions(\"-Xunknown1\")" ), expectedExitCode = 1, expectedSomeErrPatterns = listOf( "unresolved reference: CompilerOptions" ) ) - // it seems not possible to make a one-liner with the annotation, and - // annotation is the easiest available distinguishing factor for the .main.kts script - // so, considering "expecting an element" error as a success here runWithK2JVMCompiler( arrayOf( "-cp", getMainKtsClassPath().joinToString(File.pathSeparator), "-Xdefault-script-extension=.main.kts", - "-expression", - "\\@file:CompilerOptions(\"-Xunknown1\")" + "-expression=@file:CompilerOptions(\"-Xunknown1\")" ), - expectedExitCode = 1, - expectedSomeErrPatterns = listOf( - "expecting an element" - ) + expectedExitCode = 0, ) }