K2: Update extension receiver after checking in CheckExtensionReceiver

fixes receiver selection when the candidate has more that one possible
extension receiver
#KT-62129 fixed
This commit is contained in:
Ilya Chernikov
2023-09-21 17:04:02 +02:00
committed by Space Team
parent 56eedfebee
commit 141333bdcd
9 changed files with 58 additions and 10 deletions
@@ -18358,6 +18358,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/useFromAnotherModuleWithDefaultParameterValues.kt");
}
@Test
@TestMetadata("withTwoContextReceivers.kt")
public void testWithTwoContextReceivers() throws Exception {
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/withTwoContextReceivers.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP")
@TestDataPath("$PROJECT_ROOT")
@@ -18358,6 +18358,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/useFromAnotherModuleWithDefaultParameterValues.kt");
}
@Test
@TestMetadata("withTwoContextReceivers.kt")
public void testWithTwoContextReceivers() throws Exception {
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/withTwoContextReceivers.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP")
@TestDataPath("$PROJECT_ROOT")
@@ -18358,6 +18358,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/useFromAnotherModuleWithDefaultParameterValues.kt");
}
@Test
@TestMetadata("withTwoContextReceivers.kt")
public void testWithTwoContextReceivers() throws Exception {
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/withTwoContextReceivers.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP")
@TestDataPath("$PROJECT_ROOT")
@@ -126,6 +126,8 @@ object CheckExtensionReceiver : ResolutionStage() {
isDispatch = false,
)
candidate.chosenExtensionReceiver = receiver.expression
sink.yieldIfNeed()
}
@@ -0,0 +1,12 @@
// !LANGUAGE: +ContextReceivers
// TARGET_BACKEND: JVM_IR
class A { val o = "O" }
class B { val k = "K" }
val A.bar get() = o
context(A, B)
fun ok() = bar + k
fun box(): String = with(A()) { with(B()) { ok() } }
@@ -18358,6 +18358,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/useFromAnotherModuleWithDefaultParameterValues.kt");
}
@Test
@TestMetadata("withTwoContextReceivers.kt")
public void testWithTwoContextReceivers() throws Exception {
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/withTwoContextReceivers.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP")
@TestDataPath("$PROJECT_ROOT")
@@ -18358,6 +18358,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/useFromAnotherModuleWithDefaultParameterValues.kt");
}
@Test
@TestMetadata("withTwoContextReceivers.kt")
public void testWithTwoContextReceivers() throws Exception {
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/withTwoContextReceivers.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP")
@TestDataPath("$PROJECT_ROOT")
@@ -15234,6 +15234,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/useFromAnotherModuleWithDefaultParameterValues.kt");
}
@TestMetadata("withTwoContextReceivers.kt")
public void testWithTwoContextReceivers() throws Exception {
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/withTwoContextReceivers.kt");
}
@TestMetadata("compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -246,9 +246,12 @@ class ScriptingHostTest : TestCase() {
}
@Test
fun testSimpleScriptWithImplicitReceiver() {
val greeting = listOf("3")
val script = "println(length)"
fun testImplicitReceiverWithExtensionProperty() {
// emulates the appropriate gradle kotlin dsl test
val script = """
val String.implicitReceiver get() = this
require(implicitReceiver is String)
""".trimIndent()
val definition = createJvmScriptDefinitionFromTemplate<SimpleScriptTemplate>(
compilation = {
implicitReceivers(String::class)
@@ -257,13 +260,9 @@ class ScriptingHostTest : TestCase() {
implicitReceivers("abc")
}
)
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(greeting, output)
BasicJvmScriptingHost().eval(
script.toScriptSource(), definition.compilationConfiguration, definition.evaluationConfiguration
).throwOnFailure()
}
fun testScriptWithImplicitReceiversWithSameShortName() {