K2 Scripting: fix implicit receivers resolution order
#KT-65975 fixed
This commit is contained in:
committed by
Space Team
parent
1847485d28
commit
49559d2a5a
@@ -26,7 +26,7 @@ fun SessionHolder.collectTowerDataElementsForScript(owner: FirScript): TowerElem
|
|||||||
owner.symbol, receiver.typeRef.coneType, receiver.labelName, session, scopeSession,
|
owner.symbol, receiver.typeRef.coneType, receiver.labelName, session, scopeSession,
|
||||||
contextReceiverNumber = index,
|
contextReceiverNumber = index,
|
||||||
)
|
)
|
||||||
}
|
}.asReversed()
|
||||||
|
|
||||||
return TowerElementsForScript(
|
return TowerElementsForScript(
|
||||||
contextReceivers,
|
contextReceivers,
|
||||||
|
|||||||
+55
@@ -292,6 +292,61 @@ class ScriptingHostTest : TestCase() {
|
|||||||
Assert.assertEquals(result, output)
|
Assert.assertEquals(result, output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testScriptWithImplicitReceiversWithSameNamedProperty() {
|
||||||
|
val result = listOf("first")
|
||||||
|
val script = "println(v)"
|
||||||
|
val definition = createJvmScriptDefinitionFromTemplate<SimpleScriptTemplate>(
|
||||||
|
compilation = {
|
||||||
|
updateClasspath(classpathFromClass<kotlin.script.experimental.jvmhost.test.forScript.TestClass1>())
|
||||||
|
implicitReceivers(
|
||||||
|
kotlin.script.experimental.jvmhost.test.forScript.TestClass1::class,
|
||||||
|
kotlin.script.experimental.jvmhost.test.forScript.TestClass2::class
|
||||||
|
)
|
||||||
|
},
|
||||||
|
evaluation = {
|
||||||
|
implicitReceivers(
|
||||||
|
kotlin.script.experimental.jvmhost.test.forScript.TestClass1("first"),
|
||||||
|
kotlin.script.experimental.jvmhost.test.forScript.TestClass2("second")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
val output = captureOut {
|
||||||
|
val retVal = BasicJvmScriptingHost().eval(
|
||||||
|
script.toScriptSource(), definition.compilationConfiguration, definition.evaluationConfiguration
|
||||||
|
).valueOrThrow().returnValue
|
||||||
|
if (retVal is ResultValue.Error) throw retVal.error
|
||||||
|
}.lines()
|
||||||
|
Assert.assertEquals(result, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testScriptWithImplicitReceiverAndBaseClassWithSameNamedProperty() {
|
||||||
|
val result = listOf("base")
|
||||||
|
val script = "println(v)"
|
||||||
|
val definition = createJvmScriptDefinitionFromTemplate<SimpleScriptTemplate>(
|
||||||
|
compilation = {
|
||||||
|
updateClasspath(classpathFromClass<kotlin.script.experimental.jvmhost.test.forScript.TestClass1>())
|
||||||
|
implicitReceivers(
|
||||||
|
kotlin.script.experimental.jvmhost.test.forScript.TestClass1::class
|
||||||
|
)
|
||||||
|
baseClass(
|
||||||
|
kotlin.script.experimental.jvmhost.test.forScript.Base::class
|
||||||
|
)
|
||||||
|
},
|
||||||
|
evaluation = {
|
||||||
|
implicitReceivers(
|
||||||
|
kotlin.script.experimental.jvmhost.test.forScript.TestClass1("receiver")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
val output = captureOut {
|
||||||
|
val retVal = BasicJvmScriptingHost().eval(
|
||||||
|
script.toScriptSource(), definition.compilationConfiguration, definition.evaluationConfiguration
|
||||||
|
).valueOrThrow().returnValue
|
||||||
|
if (retVal is ResultValue.Error) throw retVal.error
|
||||||
|
}.lines()
|
||||||
|
Assert.assertEquals(result, output)
|
||||||
|
}
|
||||||
|
|
||||||
fun testScriptImplicitReceiversTransitiveVisibility() {
|
fun testScriptImplicitReceiversTransitiveVisibility() {
|
||||||
val result = listOf("42")
|
val result = listOf("42")
|
||||||
val script = """
|
val script = """
|
||||||
|
|||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kotlin.script.experimental.jvmhost.test.forScript
|
||||||
|
|
||||||
|
open class Base {
|
||||||
|
val v: String = "base"
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestClass1(val v: String)
|
||||||
|
class TestClass2(val v: String)
|
||||||
Reference in New Issue
Block a user