Scripting, IR: fix capturing of implicit receiver
#KT-55068 fixed
This commit is contained in:
committed by
Space Team
parent
07af2d807a
commit
42a0acac4f
+6
-2
@@ -489,18 +489,22 @@ private class ScriptToClassTransformer(
|
||||
transformAnnotations(data)
|
||||
typeRemapper.withinScope(this) {
|
||||
val newDispatchReceiverParameter = dispatchReceiverParameter?.transform(data)
|
||||
val isInScriptConstructor = this@transformFunctionChildren is IrConstructor && parent == irScript
|
||||
val dataForChildren =
|
||||
when {
|
||||
newDispatchReceiverParameter == null -> data
|
||||
|
||||
newDispatchReceiverParameter.type == scriptClassReceiver.type ->
|
||||
ScriptToClassTransformerContext(newDispatchReceiverParameter.symbol, null, null, this is IrConstructor)
|
||||
ScriptToClassTransformerContext(newDispatchReceiverParameter.symbol, null, null, isInScriptConstructor)
|
||||
|
||||
newDispatchReceiverParameter.type == data.valueParameterForFieldReceiver?.owner?.type ->
|
||||
ScriptToClassTransformerContext(
|
||||
null,
|
||||
data.fieldForScriptThis,
|
||||
newDispatchReceiverParameter.symbol,
|
||||
this is IrConstructor
|
||||
isInScriptConstructor
|
||||
)
|
||||
|
||||
else -> data
|
||||
}
|
||||
dispatchReceiverParameter = newDispatchReceiverParameter
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6, NATIVE, WASM, JVM_OLD
|
||||
// KOTLIN_SCRIPT_DEFINITION: org.jetbrains.kotlin.codegen.TestScriptWithReceivers
|
||||
|
||||
// receiver: abracadabra
|
||||
// expected: rv=cadabra
|
||||
|
||||
// KT-55068
|
||||
|
||||
class User(var property: String = drop(4))
|
||||
|
||||
val rv = User().property
|
||||
+5
@@ -29,6 +29,11 @@ public class CustomScriptCodegenTestGenerated extends AbstractCustomScriptCodege
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/customScript"), Pattern.compile("^(.*)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("captureImplicitReceiverInDefaultValue.kts")
|
||||
public void testCaptureImplicitReceiverInDefaultValue_kts() throws Exception {
|
||||
runTest("compiler/testData/codegen/customScript/captureImplicitReceiverInDefaultValue.kts");
|
||||
}
|
||||
|
||||
@TestMetadata("pathPattern5.kts")
|
||||
public void testPathPattern5_kts() throws Exception {
|
||||
runTest("compiler/testData/codegen/customScript/pathPattern5.kts");
|
||||
|
||||
+5
@@ -29,6 +29,11 @@ public class IrCustomScriptCodegenTestGenerated extends AbstractIrCustomScriptCo
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/customScript"), Pattern.compile("^(.*)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("captureImplicitReceiverInDefaultValue.kts")
|
||||
public void testCaptureImplicitReceiverInDefaultValue_kts() throws Exception {
|
||||
runTest("compiler/testData/codegen/customScript/captureImplicitReceiverInDefaultValue.kts");
|
||||
}
|
||||
|
||||
@TestMetadata("pathPattern5.kts")
|
||||
public void testPathPattern5_kts() throws Exception {
|
||||
runTest("compiler/testData/codegen/customScript/pathPattern5.kts");
|
||||
|
||||
Reference in New Issue
Block a user